Design Patterns

7 years ago Lalit Bhagtani 0

Design Patterns in Java :- A design patterns is a well described solution to a common software problem. It provides standard approach to solve problems which provide re-usability and maintainability to code. This makes code easy to understand and debug.

Design Patterns

Gang of Four (GOF)

In 1994, four authors Erich Gamma, Richard Helm, Ralph Johnson and John Vlissides published a book titled Design Patterns – Elements of Reusable Object-Oriented Software which coined the concept of Design Pattern. These authors are known as Gang of Four (GOF). According to them design patterns are primarily based on the following principles of object orientated design.

  1. Always program to an interface not to an implementation.
  2. Choose object composition over inheritance.

Design Patterns in Java are divided into three different categories – creational, structural, and behavioral patterns. Each category are defined as follows :-

  • Creational Patterns : These patterns provide a way to create objects while hiding the creation logic, here we do not create objects directly using new operator. This provides more flexibility in deciding which objects need to be created. Creational Patterns are of five different types :-
    1. Singleton Pattern
    2. Factory Pattern
    3. Abstract Factory Pattern
    4. Builder Pattern
    5. Prototype Pattern
  • Structural Patterns : These patterns provide different ways to create a class structure, for example using inheritance and composition to create a large object from small objects and to define different ways to compose objects to obtain new functionalities. Structural Patterns are of seven different types :-
    1. Adapter Pattern
    2. Composite Pattern
    3. Proxy Pattern
    4. Flyweight Pattern
    5. Facade Pattern
    6. Bridge Pattern
    7. Decorator Pattern
  • Behavioral Patterns : These patterns are used to provide better solution for the interaction between objects and to provide lose coupling and flexibility to extend them easily. Behavioral Patterns are of eleven different types :-
    1. Template Method Pattern
    2. Mediator Pattern
    3. Chain of Responsibility Pattern
    4. Observer Pattern
    5. Strategy Pattern
    6. Command Pattern
    7. State Pattern
    8. Visitor Pattern
    9. Interpreter Pattern
    10. Iterator Pattern
    11. Memento Pattern