Re: Design question: Multiplying singletons
- From: kelvSYC <kelvSYC@xxxxxxxxxxxxxxxx>
- Date: Wed, 25 Apr 2007 19:14:31 GMT
In article <oNLXh.5771$0d2.673@trndny02>, H. S. Lahman
<h.lahman@xxxxxxxxxxx> wrote:
What you seem to be describing is:
1 R1 *
[A] ------------- [B]
| 1
|
| R2
|
| *
[C]
where the requirements dictate that only one A may exist no matter how
many [B] or [C] objects there are (i.e., R1 and R2 always have the same
A on the 1-side for every B and C). So one implements [A] as a Singleton
pattern.
All that A::getInstance() is doing is providing reference for [B] or [C]
objects to use to instantiate their R1 or R2 relationship. Then
A::getB() and A::getC() just provides navigation through A when a B
needs to collaborate with a C or vice versa.
The problem is that if there are multiple [B] or [C] objects, one can't
provide that navigation with your implementation of A::getB() and
A::getC(). That is because the single A instance is actually related to
multiple Bs and Cs. So long as the [B] or [C] side is *, then one needs
a collection to manage the 1:* relationship and the accessors need to
know which particular B or C one is after within the collection:
A::getB(bID) and A::getC(cID). So...
This is a valid concern in one-to-many relationships - I'd have to take
note of that.
But suppose the relationships were one-to-one - that is, you could fold
everything in B (or C) back to A, but then A would simply balloon in
size or manageability (B or C may or may not be singleton, which would
be moot). Going back to the original question, with the one-to-one
relationship in mind, how would you keep track of the A associated with
a B (or C) if A was no longer singleton? Would the controller idea
work?
class B {
private int foo(C c);
public int bar() { return foo(A.getInstance().getC()); }
}
There's a typo: bar() returns a C. This needs to change to:
I don't get it. A.getInstance().getC() returns a C, but calling foo on
it returns an int, which bar returns.
Anyways, the example was a bit contrived so as to get the point
across...
--
I am only a mirage.
.
- Follow-Ups:
- Re: Design question: Multiplying singletons
- From: H. S. Lahman
- Re: Design question: Multiplying singletons
- References:
- Design question: Multiplying singletons
- From: kelvSYC
- Re: Design question: Multiplying singletons
- From: H. S. Lahman
- Design question: Multiplying singletons
- Prev by Date: Re: dynamic binding on parameters, how ??
- Next by Date: Re: Modeling events that occur in a game world
- Previous by thread: Re: Design question: Multiplying singletons
- Next by thread: Re: Design question: Multiplying singletons
- Index(es):
Relevant Pages
|