Describe the Singleton pattern

Experience Level: Senior
Tags: Design PatternsGang of Four (GoF)

Answer

What problem does the Singleton pattern try to solve

  • The Singleton pattern is used to enforce just one object instance, all further references refer to the same underlying instance.
  • The class itself should be responsible for creating the instance of itself

How to implement it

  • Hide the constructor so the class cannot be instantiated from the external code
  • Define a public static operation GetInstance or property Current

Other information

  • It's creational pattern
  • It was defined by Gang of Four (GoF)
Related Design Patterns job interview questions

Comments

No Comments Yet.
Be the first to tell us what you think.

Chat

Oh, the operator is not available. Leave us your comments. We will answer all your questions as soon as possible.

Comments

Anonymous
Καλησπέρα.
Anonymous
the infinteis -3/15 so 1triition / infinet
Anonymous
e
Anonymous
<a href="https://inspirum.pl "
Anonymous
[url]https://inspirum.pl[/url]
LaceJaguar65
e
LaceJaguar65
e
LaceJaguar65
e
LaceJaguar65
e
LaceJaguar65
e
LaceJaguar65
e
LaceJaguar65
e
LaceJaguar65
e
LaceJaguar65
e
LaceJaguar65
e
LaceJaguar65
e
LaceJaguar65
e
LaceJaguar65
e
LaceJaguar65
e
LaceJaguar65
e
LaceJaguar65
e
LaceJaguar65
e
LaceJaguar65
e
LaceJaguar65
e
LaceJaguar65
e