Design Patterns

In core Java, there are mainly three types of design patterns, which are further divided into their sub-parts:

1. Creational Design Pattern : Creational design patterns are concerned with the way of creating objects.

  1. Factory Pattern
  2. Abstract Factory Pattern
  3. Singleton Pattern
  4. Prototype Pattern
  5. Builder Pattern.

2. Structural Design Pattern : Structural design patterns are concerned with how classes and objects can be composed, to form larger structures. The structural design patterns simplifies the structure by identifying the relationships.

  1. Adapter Pattern
  2. Bridge Pattern
  3. Composite Pattern
  4. Decorator Pattern
  5. Facade Pattern
  6. Flyweight Pattern
  7. Proxy Pattern

3. Behavioral Design Pattern : Behavioral design patterns are concerned with the interaction and responsibility of objects. In these design patterns,the interaction between the objects should be in such a way that they can easily talk to each other and still should be loosely coupled.

  1. Chain Of Responsibility Pattern
  2. Command Pattern
  3. Interpreter Pattern
  4. Iterator Pattern
  5. Mediator Pattern
  6. Memento Pattern
  7. Observer Pattern
  8. State Pattern
  9. Strategy Pattern
  10. Template Pattern
  11. Visitor Pattern

Factory Pattern (Creational Pattern)

In Factory pattern, we create object without exposing the creation logic to the client and refer to newly created object using a common interface.



Singleton Pattern (Creational Pattern)

This pattern involves a single class which is responsible to create an object while making sure that only single object gets created. This class provides a way to access its only object which can be accessed directly without need to instantiate the object of the class.


Proxy Pattern (Structural Pattern)

In proxy pattern, a class represents functionality of another class. In proxy pattern, we create object having original object to interface its functionality to outer world.



Facade Pattern (Structural Pattern)

Facade pattern hides the complexities of the system and provides an interface to the client using which the client can access the system. This pattern adds an interface to existing system to hide its complexities.This pattern involves a single class which provides simplified methods required by client and delegates calls to methods of existing system classes.




Adapter Pattern (Structural Pattern)

Adapter pattern works as a bridge between two incompatible interfaces. This pattern combines the capability of two independent interfaces.This pattern involves a single class which is responsible to join functionalities of independent or incompatible interfaces. A real life example could be a case of card reader which acts as an adapter between memory card and a laptop. You plugin the memory card into card reader and card reader into the laptop so that memory card can be read via laptop.



Prototype pattern (Creational Pattern)

Prototype pattern refers to creating duplicate object while keeping performance in mind. This pattern provides one of the best ways to create an object.This pattern involves implementing a prototype interface which tells to create a clone of the current object. This pattern is used when creation of object directly is costly. For example, an object is to be created after a costly database operation. We can cache the object, returns its clone on next request and update the database as and when needed thus reducing database calls.

No comments:

Post a Comment