From: John A. T. <ja...@ja...> - 2008-11-07 15:55:57
|
Erik Vos wrote: > I consider a class "getInstance()" method to be a perfectly acceptable way > to get access to the instance of a Singleton. Whether or not singletons are > a good idea is a different discussion. In general I see no problems with it, > except that in Rails we should get rid of most existing singletons if we > want to aim for a multi-game server. > > However, I don't understand what you mean with "global variables" in this > context. And I certainly don't see any connection between variables being > global (or whatever) and the use of class getInstance methods. > > Puzzled, > The argument against singletons is that it makes testing hard, as you can't easily replace the underlying object with a mocked instance. The alternative is using dependency injection, such as Guice. Also see http://code.google.com/p/google-singleton-detector/wiki/WhySingletonsAreControversial (which is a Google project to help detect various kinds of global state). -- John A. Tamplin ja...@ja... 770/436-5387 HOME 4116 Manson Ave Smyrna, GA 30082-3723 |