CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Join Date
    Jan 2003
    Location
    Singapore
    Posts
    5

    Tips need for building an application framework

    Hi,

    Can some of you give me some tips about how to build an application framework?

    What I have done is;

    (1) Define a base class with some virtual functions (abstract class)
    (2) Derive a class from base and implement all the functions
    (3) Build implementation into a static library

    (3) Provide a header file which include only base class & library to client application (I want to hide all the impelmentation details from client application.
    (4) in client application, declare a void pointer
    (5) in client app, try to downcast pointer to derived class in library (no compiling error)
    (6) make a call to functions (e.g ptr->method1, compilig error ???)

    I know some wrong, but don't know where problem is? Is it the right way to build an application framework?

    Please help,

    Thanks in advance,
    Last edited by D002199; January 27th, 2003 at 06:32 AM.

  2. #2
    Join Date
    Nov 2002
    Location
    Foggy California
    Posts
    1,245
    There is no need to derive a class from a virtual base class to hide implementation details -- "implementation" being the code behind member functions. If you want to hide structure details, then you can do something like:

    Code:
    // Definition of _MyClassPrvtData in some C/C++ file.
    typedef struct _MyClassPrvtData* MyClassPrvtData;
    
    class MyClass
    {
        MyClassPrvtData data;
    
    public:
        // ...
    };
    That being said, don't worry about this in practice (unless you have a really, really good reason to). The fact that you declare data in your private section of a class tells the users of your library to not rely on anything in it because you may change how you implement that part.

    - Kevin

  3. #3
    Join Date
    Sep 2002
    Posts
    1,747
    Here are some points that I would suggest:
    • You don't necessarily need a base object for the hierarchy of your entire framework. Some frameworks (MFC, Qt, etc.) do this, but these often become restricting due to the coupling (particularly if the framework is to grow and change), and flatter code is often desirable.
    • Implementation hiding does not mean hiding all derived headers. I doubt your contention that this compiles, as the syntactic analysis phase could not complete without declarations. Often, implementation hiding is done with a Bridge pattern or pimpl (similar ideologies of using a compiled implementation class contained and used in the interface class).
    • Get rid of the void pointer. Your framework has just lost all type safety and might as well be assembly. Use true polymorphism.
    */*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/

    "It's hard to believe in something you don't understand." -- the sidhi X-files episode

    galathaea: prankster, fablist, magician, liar

  4. #4
    Join Date
    Jan 2003
    Location
    Singapore
    Posts
    5
    Thank you very much for your suggestion!

    I will do some practices to really digest what you have suggest,


    By the way, where can I find some articles regarding "Bridge Patten" ?


    Thanks again,

  5. #5
    Join Date
    Sep 2002
    Posts
    1,747
    Here is one source of information. But I just did a google search on:
    "hiding implementation" bridge
    to find it, and alot of other good sources popped up as well!
    */*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/

    "It's hard to believe in something you don't understand." -- the sidhi X-files episode

    galathaea: prankster, fablist, magician, liar

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured