[prev in list] [next in list] [prev in thread] [next in thread] 

List:       ruby-talk
Subject:    Re: Singleton Class or Module Functions?
From:       "Jason Voegele" <jason () jvoegele ! com>
Date:       2004-10-21 17:52:41
Message-ID: 14477.192.146.101.26.1098381158.squirrel () 192 ! 146 ! 101 ! 26
[Download RAW message or body]

Brian Candler said:
> Writing as a Class may make sense if there's any chance you might want to
> create more than one instance in the future.

I agree with Brian's assessment, and furthermore IMO Singleton is an
anti-pattern.  The number of instances of a given class is an application
level decision, not something that should be hard-wired into the class
itself.  If you use Dependency Injection (possibly with the help of a
container like Copland) the need for singletons is drastically reduced,
perhaps eliminated altogether.

See the article linked below for a discussion of how "Inversion of
Control"/"Dependency Injection" can help eliminate Singletons.  The
article is about the Spring framework for Java, but the concepts should
map fairly straightforwardly to Ruby and Copland.

http://www.theserverside.com/articles/article.tss?l=SpringFramework

-- 
Jason Voegele
"There is an essential core at the center of each man and woman that
remains unaltered no matter how life's externals may be transformed
or recombined. But it's smaller than we think."
    -- Gene Wolfe, The Book of the Long Sun


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic