Re: Singletons
From: Ilja Preuß (it_at_iljapreuss.de)
Date: 01/19/05
- Previous message: H. S. Lahman: "Re: new here, my lang project..."
- In reply to: Thomas Gagne: "Re: Singletons"
- Next in thread: Thomas Gagne: "Re: Singletons"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Wed, 19 Jan 2005 19:40:13 +0100
Thomas Gagne wrote:
> People abuse getters and setters? They must be evil and avoided.
Well, I do use getters and setters. But I also find that when I think about
alternative designs that don't need them, I regularly come up with better
designs.
> People abuse singletons? They must be evil and avoided.
It's not just that people abuse singletons. It's that I can't see many
reasons to use one.
> People abuse gotos? casts? void *? char *?
The latter must come from a language I'm not literate enough in to comment,
but I'm quite sure that it pays off to at least be suspicious of gotos and
casts.
> People may call functions you've documented as "insiders-only"? Make
> them private and don't let them.
> People may override a method you don't think they should?
> People may add a function to your precious class you didn't think of?
> Make it so they can't. Make your intentions so ironclad that no one
> can do anything other than what you intended to be done the way you
> intended it should be done.
Well, I actually find it to be quite usefull from time to time to have those
language features at my disposal when I later can undo that decision by
changing the code. I agree, though, that it tends to criple an API that you
can't change.
> Just because a programmer may trip themselves up is a poor excuse to
> language design.
And that's exactly a reason *not* to use a Singleton. Just because currently
you only want to have one instance and fear that someone might trip himself
by creating a second one is a bad excuse for cripling a class by not
allowing more than one instance, and coupling the whole system to that
decision so that it later gets a real pain to change!
Cheers, Ilja
- Previous message: H. S. Lahman: "Re: new here, my lang project..."
- In reply to: Thomas Gagne: "Re: Singletons"
- Next in thread: Thomas Gagne: "Re: Singletons"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]