Content area
Full text
A Singleton design pattern ensures that only one instance of a class is created.
Imagine a disorganised wardrobe with heaps of clothes in every section. How would you organise it? When I asked my students this question, I got the following answers: Empty the wardrobe Arrange the clothes:
* on the basis of the most frequently used ones
* or the favourite ones
* or by their type (e.g., Indian/Western)
3. Fix each section for each category and arrange the clothes accordingly
If a similar problem occurs in another context, such as when re-arranging a bookshelf, the same solution can be reused. This is the basic principle behind design patterns. With respect to object-oriented software engineering, a design pattern describes a redundant problem and provides a reusable solution.
Types of design patterns
Design patterns have been categorised by the Gang of Four or GoF (Gamma, Helm, Johnson and Vlissides) into three types: Creational - Patterns that deal with object creation Structural - Patterns that deal with the composition of classes or objects, and their relationships Behavioural - Patterns that focus on how objects...