I am not sure about why (or whether) Gamma said that, but the singleton pattern, as is it commonly used, does offend some OO purists. The main complaint is that the singleton class does two distinct, unrelated things - (1) at the class level, control the number of instances and (2) at the instance level, whatever it is supposed to do (like control a shared resource, for example).
With the presence of namespaces (like in C++ and Java packages), there is no reason why these two functionalities cannot be put into two different classes that are exclusively present in the same namespace. In Java world, this means that there would a public InstanceController class and a package level SingletonInstance class in the same package, say, mypackage.singleton. There would be no other classes in that package. The clients would only deal with the InstanceController class to get hold of SingleInstance instances. This way, if the requirements for one of these functionalities changes, we can modify and test one class without affecting the other. Also, since it the most "popular" pattern, it is also the most widely misused one. Any software project today is filled with singletons, simply because it is (1) easy to do and (2) "patterns are cool and good". People don't seem to understand the forces that give rise to the need for this pattern (or any pattern for that matter). reg, Sriram -----Original Message----- From: Arno Haase [mailto:[EMAIL PROTECTED] Sent: Thursday, December 04, 2003 10:19 AM To: Patterns-Discussion Subject: [patterns-discussion] Erich Gamma quote Hi, I heard that Erich Gamma once said in an interview that given the chance to make some change to the GOF book, he would remove the Singleton pattern. Do any of you have a reference for that (or rather, for what he actually said, because it likely got distorted in the retelling)? Thanks a lot in advance - Arno _______________________________________________ patterns-discussion mailing list [EMAIL PROTECTED] http://mail.cs.uiuc.edu/mailman/listinfo/patterns-discussion _______________________________________________ patterns-discussion mailing list [EMAIL PROTECTED] http://mail.cs.uiuc.edu/mailman/listinfo/patterns-discussion
