Singleton Pattern solves problem like
- How to ensure that a class has only one instance
- How can the sole instance of a class be accessed globally
Applicability:
- Hide the constructor of the class using private access specifier
- Define a static function that returns the sole instance of the object created in the constructor.
Example by Code:
Class Logger{
private:
Logger(){
instance = new Logger();
}
public:
static getInstance(){
return instance;
}
}
Top comments (0)