From ruby-talk Thu Oct 21 17:52:41 2004 From: "Jason Voegele" Date: Thu, 21 Oct 2004 17:52:41 +0000 To: ruby-talk Subject: Re: Singleton Class or Module Functions? Message-Id: <14477.192.146.101.26.1098381158.squirrel () 192 ! 146 ! 101 ! 26> X-MARC-Message: https://marc.info/?l=ruby-talk&m=109838118610452 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