Re: Can use of singletons denote poor project design?
- From: "Ed" <iamfractal@xxxxxxxxxxx>
- Date: 25 Feb 2006 08:04:33 -0800
Daniel Parker wrote:
Phlip wrote:
[X-posted to comp.object and followups set]
John Fly wrote:
Right now I use [singletons] for :
Logging server : A central message storage and distribution to N number
of reports/logs)
Program State : Again a central point to keep track of program status.
Central Data representation
Regards,
Daniel Parker
To answer the question in the subject: yes.
Further, to rephrase the quesiton as, "Can use of X denote poor project
design?" where X is any design pattern/documentation/metric/etc., the
answer is probably: yes. Anything can be overused/abused.
To focus, however, on Singletons:
"It is a truth universally acknowledged, that a singleton in possession
of complex behaviour, must be in want of a refactoring."
It is true, furthermore, that all singletons in a project can be
replaced by one, less complex singleton: I tend to have only one
signleton in my code, which is a ConcreteRegistry. During start-up, all
the other bits register themselves in the registry, for example the
Model, View, and Controller interfaces. Then they can all access one
another by:
class ConcreteView implements View {
void doSomething() {
Model model = ConcreteRegistry.getInstance().getModel();
}
}
This tends to lead to the result that a lot of the classes depend on
the singleton, but this is not necessarily a bad thing as the
singleton's behaviour is rigourously limited to storing and serving
interfaces, and the singleton itself is not dependent on the methods of
the interfaces that it stores.
The point is: here's a singleton with loads of dependencies on it, yet
this isn't, I think, bad design. So although the answer to the
subject-line question is yes, the converse is not true: using
singletons does not imply bad design.
..ed
--
www.EdmundKirwan.com - Home of The Fractal Class Composition
.
- Follow-Ups:
- Re: Can use of singletons denote poor project design?
- From: Daniel T.
- Re: Can use of singletons denote poor project design?
- References:
- Re: Can use of singletons denote poor project design?
- From: Daniel Parker
- Re: Can use of singletons denote poor project design?
- Prev by Date: Re: Can use of singletons denote poor project design?
- Next by Date: Re: Can use of singletons denote poor project design?
- Previous by thread: Re: Can use of singletons denote poor project design?
- Next by thread: Re: Can use of singletons denote poor project design?
- Index(es):
Relevant Pages
|