There has been discussion of Singleton in the last week or two on the intermediate forum, try: this thread,this one, or this third one. See whether any of them helps you. Any more questions, I am sure people will be happy to help.
posted 12 years ago
Oh, and there are definitely versions of the Singleton pattern which create two objects.
Well the idea behind the Singlenton pattern is to have one sole instance of a kind object.
Typically it means one sole instance of a class. However, that is not an absolute requirement. The Gang of Four (GoF), authors of Design Patterns, Elements of Reusable Object-Oriented Software talk about the posibility of having a registry of Singlentons within the Singleton class itself.
Based on this principle I would say that the Singlenton is a kind of class that guarantees a limited and predefined existance of instances of a class. Almost ever this limited number is one, but that is not a requirement.
In a Singleton that uses a registry, you call the getInstance method and the Singleton goes over the singlenton registry and checks if the instance you require already exists, if so, returns that instance, if not, a new instance is created.
In this case, the Singlenton is based on the principle of keeping one sole instance for every possible state of the Singleton class.
Still, that should be considered a Singleton, at least according to GoF.