FuzzDuck
FuzzDuck
Singleton pattern
FuzzDuck
Singleton pattern

Singleton Pattern

The Singleton Pattern is built to assure that only one instance of a specific class is made. It consist of a method “getInstance()”, which checks itself to see whether another instance exists. If not, it allows itself to create an instance. If there is one however, it returns that instance instead of creating another one.

Singleton Pattern UML

Only one in command

Sometimes more than one command can be confusing. So to ensure that only one person makes the call we use the singleton pattern to create only one instance of the commander. If the create method is called yet again, the original commander will be returned as a result.

Only one pet

The childrens want a new pet. But the rule says only to have one pet in the household. When an attempt is made to bring in a new pet, the acts is stopped, and the old pet is being referred to.