Design patterns implementation examples

Singleton

Definition:

Gives a client an access to only one class instance and provides global method to do that.


Example:

God analogy would be a choice of husband/wife. It is possible to have only one husband/wife at one time - according to the law. We are able to love only one person at one time.


C++ code:

/src/singleton.cpp
Download source code

C++ code:

/src/singletonlazy.cpp
Download source code

Sigleton UML class diagram:
Sigleton UML class diagram

Sigleton UML sequence diagram:
Sigleton UML sequence diagram