CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Oct 1999
    Posts
    3

    Should I further encapsulate existing classes

    For example, when creating objects
    from existing classes developed by others:

    Class_Custom* pMyObject1 = new RefClass1;
    Class_Custom* pMyObject2 = new RefClass2;
    pMyObject->function1(...);
    ...

    After using, I would need to manually delete it, say:
    delete MyObject1;
    delete MyObject2;

    Question is should i further encapsulate these
    with a higher class?
    for example, to provide auto cleanup?

    Thanks and regards

    LWS










  2. #2
    Join Date
    Apr 1999
    Posts
    27,449

    Re: Should I further encapsulate existing classes

    If you want to provide auto cleanup, you should take a look at the STL auto_ptr class.

    Regards,

    Paul McKenzie


  3. #3
    Join Date
    May 1999
    Location
    Slovenia (currently: Germany)
    Posts
    249

    Re: Should I further encapsulate existing classes

    Depending on your intention. For auto clean up in any circumstances including exceptions (except for longjmp) use auto_ptr, it kills pointers in destructors.

    But if your question is how to structure your application then perhaps you should use the facade pattern meaning that you provide basic operations that these classes do in one class and then delegate work to other classes. Well it works for small objects (small number of system operations), but if your object is too large you need higher level of abstraction and then you can use the facade again...

    Sincerely,
    Tomaz


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