Click to See Complete Forum and Search --> : Should I further encapsulate existing classes


xxlwsxx
October 6th, 1999, 08:47 AM
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

Paul McKenzie
October 6th, 1999, 01:02 PM
If you want to provide auto cleanup, you should take a look at the STL auto_ptr class.

Regards,

Paul McKenzie

Tomaz Stih
October 7th, 1999, 04:36 AM
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