Design Patterns
Let’s know about why we need design patterns in any architecture of software and assume in real world also. If we want to buy one product in super market in traditional way. First of all used to check it’s price, product quality and brand travel shop by shop ask shop keepers, but as in E-commerce they have some predefined algorithms we make comparison then and there only , no need to travel ask somebody and cross verify that means we have ready made solution to buy our product we makes shopping very ease.
In the above scenario, like we have already solved problems to make use of object or properties very easily, there comes to picture of Design Patterns which makes use of creation of object, behaviour of object, structural patterns as the name we have classified as 3 types of design patterns.
- Creational design pattern
- Behavioral design pattern
- Structural design pattern
In this article we talk about creational patterns, they are sub classified as 4 types are Singleton, Factory, Abstract Factory, etc.
Singleton : Pattern allow us to create one object at any number of invocation, this can be achieved by making constructor as private so that it can create object inside that class only, creating object inside class and access from other class because when we create object automatically call constructor of class then create object.
public class Singleton{ private Singleton(){} } //pseudo code snippet
Singleton can have various scope like synchronized, lazy, etc. discuss in later concepts.