Design Pattern
Design Pattern
-> Desing patterns are well proved solution of commonly ocuuring problems in
software design.
-> In software engineering, a design pattern is a general repeatable solution
to a commonly occurring problem in software design.
-> It is a description or template for how to solve a problem that can be
used in many different situations.
-> In core java, there are mainly three types of design patterns, which are further
divided into their sub-parts:
In Detail
A. Creational Design Pattern
-> Creational design patterns are concerned with the way of creating objects
1. Factory Pattern
-> Define an interface for creating an object, but let subclasses
decide which class to instantiate.
-> It promotes the loose-coupling by eliminating the need to bind
application-specific classes into the code
-> Example : Calculate Electricity Bill
-> On the basis of plan name (domestic, commercial,
institutional) and rate we can generate/calculate electricity bill
3. Singleton Pattern
-> Define a class that has only one instance and provides a global
point of access to it.
-> There are two forms of singleton design pattern
1. Early Instantiation: creation of instance at load time.
2. Lazy Instantiation: creation of instance when required.
4. Prototype Pattern
-
5. Builder Pattern
-