Lambda the Ultimate

inactiveTopic Classes Containing Large Classes
started 6/27/2001; 2:21:56 AM - last post 6/27/2001; 12:57:57 PM
heherson - Classes Containing Large Classes  blueArrow
6/27/2001; 2:21:56 AM (reads: 570, responses: 1)
What is the best approach in storing a large class (A) in another class(B)?

a.) store the class(A) pointers to class (B) b.) store the class(A) to class(B)

The problem with the first is on the responsibility of first is on the responsibility of destroying instances of A. B will have to destroy objects he did not create.

On the other hand, the problem with the second approach is speed. B will have to create a new instance of A to store.

Any other options? comments?

Chris Rathman - Re: Classes Containing Large Classes  blueArrow
6/27/2001; 12:57:57 PM (reads: 616, responses: 0)
Couple of questions. First, are we really talking about Classes here, or are we speaking of Objects? It sounds as if you want a one-to-one relationship between the containing object and the contained (using parent-child terminology confuses the issue between class-subclass and the has-a relationship).

Second, what OO language are we talking about? I would assume that it's a language that does not have automatic garbage collection C++ most likely, since you are fretting over destructors. If it is C++, that language was probably chosen as a function of it's ability to produce fast executables - so you are probabably just going to have to bite the bullet and manage the destruction manually. In languages with GC, the first option is almost always prefered based on trying to maximize the decoupling between classes and objects.