Singleton

Originally published 2016-02-22 · Boris Ivanov

1. Usage

Class which has Single Instance and Global access hrough all application.

2. UML class diagram

3. Pros

Controlled access to single object.

4. Cons

Can be harmful in big complex system which need to be scaled.
Can complicate TDD based programming.

5. Source code


class Singleton{
private:
    Singleton(){};
public:
    static Singleton& getInstance(){
        static Singleton instance;
        return instance;
    }
};