Re: Managing multiple instances



On 28 Apr 2006 14:00:59 -0700, Benjamin M. Stocks wrote:

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

= factory

and provide the instance number of that object that is
requested.

= identity

Multiple instances of the same object may be kept in the
data structure.

= bag (of class-wide objects)

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.

= persistence

(no problem so far)

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.

Identity should be a private type. It is in general a bad idea to assume
that it is a number.

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.

Implementing persistency you should take care on dependencies between
objects. The base type of a persistent object should have a method: "get me
all objects you need." The objects from this set (not a bag) should be
stored / restored before the object. The dependencies form an order
relation, but to map it on object's IDs would be a bad idea.

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.

Yes, you should decouple IDs from dependencies. Note also that you probably
would need also external IDs, like DB keys. To manage all three as if they
were one is a nightmare, especially if the DB layer is decoupled (as it
should) and can be switched on the fly.

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.

If you can Ada 95 you could take a look at persistence implementation at my
site:

http://www.dmitry-kazakov.de/ada/components.htm#persistent_objects

--
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de
.



Relevant Pages

  • Re: Static vs. Dynamic typing (big advantage or not)---WAS: c.programming: OOP and memory management
    ... >> representation in a file or on a stream. ... I am afraid I do not see which module has access to the data structure ... version would not need the dictionary, and the score module would not ... thought was the accepted definition of persistence). ...
    (comp.programming)
  • Re: Static vs. Dynamic typing (big advantage or not)---WAS: c.programming: OOP and memory management
    ... >> representation in a file or on a stream. ... I am afraid I do not see which module has access to the data structure ... version would not need the dictionary, and the score module would not ... thought was the accepted definition of persistence). ...
    (comp.object)
  • Re: What does it mean to set large fields to null
    ... enough memory to load the graphic data into memory, ... It works hand-in-hand with the finalizer to provide client code with a well-defined API for ensuring that resources .NET has no way to explicitly manage are still released in a timely way when the client code is done with them, and a back-up system in case the client code has a bug and fails to release those resources explicitly. ... Even if you did have a data structure that could potentially allocate a large amount of memory and then later have a sensible use case where you would want to release that memory without releasing the entire data structure at all, I don't really feel that IDisposable is the right way to go about it. ... I agree with the design found, for example, in the Listclass where there's an explicit method specific to the type to accomplish that " method). ...
    (microsoft.public.dotnet.languages.csharp)
  • Managing multiple instances
    ... I'm working on an application where a number of what I will call core ... objects are maintained within a single data structure. ... As I'm sure you guessed by now changing the initialization order of the ... instance numbers (that can then be referenced from within client code) ...
    (comp.object)
  • Re: Is there a better way to do this
    ... well after reading your question and the comments ... you change the data structure you must change the data logic in the BL ... distributed design pattern, or ask here :-) ... I am thinking of creating a base class with has all the column as the ...
    (microsoft.public.dotnet.languages.vb)