The singleton design pattern in D, C++ and Java

Jonathan M Davis jmdavisprog at gmail.com
Fri Jul 16 11:40:50 PDT 2010


On Friday, July 16, 2010 11:21:28 Nick Sabalausky wrote:
> "Ali Çehreli" <acehreli at yahoo.com> wrote in message
> news:i1q4bk$21jp$1 at digitalmars.com...
> 
> > Justin Johansson wrote:
> >> Which language out of C++, D and Java does this classical
> >> "GoF" (gang-of-four***) design pattern best?
> > 
> > Are we still talking singleton? I thought that it is considered an
> > anti-pattern already. :)
> > 
> > As a teaser: What problem does it solve that can't be solved by creating
> > just one object of a type?
> 
> In languages that don't allow functions outside a class, they're useful as
> a make-shift substitute for a module with free-floating functions. Or at
> least if you count static classes as a form of singleton, anyway.

I actually would have considered that to be more of a "nullington," since  the 
class can't instatiated at all. All it really is is a way to namespace the 
functions, since functionally-speaking, the class only serves as a namespace 
rather than a real class.

Personally, I do use singleton from time-to-time and have found it quite useful. 
I wasn't aware that anyone thought that it was a bad idea.

- Jonathan M Davis


More information about the Digitalmars-d mailing list