Singleton

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;
    }
};

Leave a Reply

Your email address will not be published. Required fields are marked *