Managing multiple instances
- From: "Benjamin M. Stocks" <stocksb@xxxxxxxx>
- Date: 28 Apr 2006 14:00:59 -0700
Hello all,
I'm working on an application where a number of what I will call core
objects are maintained within a single data structure. Each class that
must persist for the lifetime of the application inherits from the same
base class and then adds itself to a data structure of that base class
type.
When other parts of the application need to access a particular
instance of a specific object they request the object by a type
enumeration and provide the instance number of that object that is
requested. Multiple instances of the same object may be kept in the
data structure. I did not design this and don't believe in "all the
core application classes should inherit from X and they all should be
stored in the SAME data structure" but I have to work with it. So an
object is stored and retrieved according to a class identifier and the
instance number of objects with that class identifer.
So here's the rub that I'm working on now: the instance numbers of the
different objects were assigned based on the order in which the objects
were added to the data structure. So if I add three instances of class
A the first instance added would get instance identifier 1, the next
would get 2 and the last would get 3. Much of the client code within
the same application was written to request a hard coded instance
number of a class when they needed access to that instance.
As I'm sure you guessed by now changing the initialization order of the
product caused many of the instance numbers stored in the data
structure to change breaking the hard coded clients. As a first step to
improving this design I'm trying to replace the implicit assigning of
instance numbers with explicit instance numbers so changing the
initialization order will no longer break the clients.
And finally the issue I ran into: I have a class whose instances are
stored in this "one data structure to hold them all" (call it class A),
however this class is created within another class (call it class B) of
which multiple instances are created from within another class (class
C). IOW class C contains 2 instances of B each of which contain an
instance of A. So when creating instances of class A I cannot provide a
simple enumeration of the instance number when adding to the data
structure or the instance numbers will not be unique.
I'm thinking this data structure design is falling apart rapidly but
its so deeply integrated into the product redesigning it may not be
feasible right now. But I'm really stuck on how to create unique
instance numbers (that can then be referenced from within client code)
when the objects to be added to the data structure are created from
within objects that may also have multiple instances.
Thanks for reading this far. Any suggestions?
Thanks in advance,
Ben
.
- Follow-Ups:
- Re: Managing multiple instances
- From: H. S. Lahman
- Re: Managing multiple instances
- From: AndyW
- Re: Managing multiple instances
- From: Dmitry A. Kazakov
- Re: Managing multiple instances
- From: Laurent Bossavit
- Re: Managing multiple instances
- From: Laurent Bossavit
- Re: Managing multiple instances
- From: Daniel T.
- Re: Managing multiple instances
- Prev by Date: Re: Question on LSP
- Next by Date: Re: Managing multiple instances
- Previous by thread: Re: Modelling an OO data structure
- Next by thread: Re: Managing multiple instances
- Index(es):
Relevant Pages
|