Re: Managing multiple instances



Benjamin M. Stocks wrote:

class C (one) ---> class B (many) --> class A (one)

Is what I think you have.


Yes. That's the most prevalent example of this issue. Class A is stored
in this data structure so if you create two instances of class C you
wind up with multiple instances of class A and from within the context
of class B there is no way to explicity give class A an identifier that
would be unique and meaningful.

You could try some hierarchical naming - either as string (e.g. "MeaningfulNameOfInstanceOfB.MeaningfulNameOfInstanceOfA") or as calculated integers (e.g. 256*IDOfB + IDOfA).

However, I am puzzled by something else. If I understand correctly you have following conditions:
1) Multiple instances of B create their own instances of A.
2) Some other place in code (not methods of class B) wants to retrieve the specific instance of A.

Now it seems to me that you should either access A via its B owner (in other words get specific B first, then use it to get its A instance), or that B shouldn't be the creator of A. It's hard to tell though, without more specific description.

Sasa
.