Re: Design question: Multiplying singletons



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.
.



Relevant Pages

  • Re: multiple inheritance?
    ... spellchecker object, ... instantiate another one in code, now I have two spellchecker objects. ... private static $singleton = null; ... possibility of ambiguous methods of aggregated objects. ...
    (comp.lang.php)
  • Re: Getters and Setters
    ... public int getBar() ... The basic principle behind encapsulation is information hiding. ... private int value; ...
    (comp.lang.java.programmer)
  • RE: How to draw custom title bars on MDI child forms?
    ... The normal title bar background can be replaced with a bmp image. ... int titleheight = 0; ... g.FillRectangle(Brushes.Blue, 0, titleheight, borderwidth, ...
    (microsoft.public.dotnet.framework.windowsforms)
  • Re: Learning C, Trying to Understand & (unary op)
    ... void swap(int x, int y) ... int tmp; ... The formal parameters x and y are different objects from foo and bar; ...
    (comp.lang.c)
  • Re: singleton COM Service and FinalRelease()
    ... Use an internal C++ singleton that you instantiate ... Even with the LocalSystem account having launch ...
    (microsoft.public.vc.atl)