Thursday 22 June 2017

Software Engineering: Singleton Pattern

Object Creation - Singleton

Intent
This design pattern restricts the instantiation of a class to one object. The purpose of this is to control object creation by keeping constructor private. This applies global access to the instance. 

How is this applied?
  • Make the constructor in the class as private, this stops us from creating another object of this outside of its class. 
  • This helps us to keep only one instance of a class at any time.

Examples of usage?
For a database, you may only want one connection per user of an application. 


UML diagram representation
https://en.wikipedia.org/wiki/Singleton_pattern#/media/File:Singleton_UML_class_diagram.svg


More to follow...

No comments:

Post a Comment

Software Engineering: Bad Smells! (Smelly code)

Bad Smells! What are bad smells? This refers to any symptom in the source code of a program that possibly indicates a deeper problem.  ...