Thursday 3 May 2018

What is a singleton pattern?

Purpose:
  • Design pattern knowledge is a good indicator of programmer competency.
  • The lowest bar and easiest example is the Singleton
  • This is basically an idiot test to see if a developer has any pattern knowledge.
  • Not being able to answer this question would be a serious concern.

Potential Answer:
The singleton pattern is a software design pattern that restricts the instantiation of a class to one object.

If you want to stand out perhaps raise how the singleton is overused and can be considered an anti-pattern when used incorrectly:

  • Introduces unnecessary restrictions when a sole instance not really required
  • Singleton makes code more complex, less useful and harder to tests
  • Debugging can be hard to figure out which code path lead to singleton's current state
  • Memory allocated cannot be freed
  • Excessive use will promote procedural programming over object orientated

No comments:

Post a Comment