The singleton pattern is a software design pattern that restricts the instantiation of a class to one “single” instance. This is useful when exactly one object is needed to coordinate actions across the system.

In C#, you use the “static” declaration.

The singleton design pattern solves problems like:[5]

  • How can it be ensured that a class has only one instance?
  • How can the sole instance of a class be accessed easily?
  • How can a class control its instantiation?
  • How can the number of instances of a class be restricted?

Example Use:

  • Store global variables.
  • Helper classes.
  • Quick access to methods.
  • No need to initial object.

Sources:

https://en.wikipedia.org/wiki/Singleton_pattern

Last modified: March 22, 2019

Author

Comments

Write a Reply or Comment