Re: Managing multiple instances
- From: Laurent Bossavit <laurent@xxxxxxxxxxxxxxxxxxxx>
- Date: Sun, 30 Apr 2006 19:09:23 +0200
Ben,
I wanted to start improving this design by suppling
the identifier rather than leaving it up to the data
structure to assign the identifier.
Which sounds like a good idea. That would bring together three
responsibilities which sound like a consistent package:
- creating instances of a class (say A)
- assigning identifiers to instances
- remembering which identifiers point to which instances
Possible but then how does the identifier get shared with the client
code so it can look up the object in the data structure?
Going back to the example we were discussing, you'd need to set up some
collaboration between B and C. Callbacks would work:
....instance of C is created: C.1 ...
... C.1 creates an instance of B (B.1), passing a pointer to itself
... B.1 asks its "parent" C for an "A identifier" (yielding, say, 1)
... B.1 creates an instance of A (A.1) and assigns it identifier 1
... C.1 creates an instance of B (B.2), passing a pointer to itself
... B.2 asks its "parent" C for an "A identifier" (yielding, say, 2)
... B.2 creates an instance of A (A.2) and assigns it identifier 2
Get your hands on a copy of Michael Feather's /Working Effectively With
Legacy Code/... Seems to have been written just for you.
I own it, can you suggest a particular section?
Well, this "data structure" sounds like it's effectively a collection of
globals, so I'd have a second look at the sections relevant to
mitigating the ill effects of global references.
Laurent
.
- References:
- Managing multiple instances
- From: Benjamin M. Stocks
- Re: Managing multiple instances
- From: Laurent Bossavit
- Re: Managing multiple instances
- From: Benjamin M. Stocks
- Managing multiple instances
- Prev by Date: Re: Thinking in OO
- Next by Date: Re: Managing multiple instances
- Previous by thread: Re: Managing multiple instances
- Next by thread: Re: Managing multiple instances
- Index(es):
Relevant Pages
|