Java Design Patterns Tutorial - Java Design Pattern Introduction








A design pattern is a well-proved solution for solving the specific problem/task.

For example, to create a class for which only a single instance should be created and that single object can be used by all other classes, use Singleton design pattern.

Design patterns are programming language independent, it is for solving the common object-oriented design problems.

A design pattern represents an idea, not an implementation.

By using the design patterns we can make our code more flexible, reusable and maintainable.

Java itself internally follows design patterns.

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

  • Creational Design Pattern
    1. Factory Pattern
    2. Abstract Factory Pattern
    3. Singleton Pattern
    4. Prototype Pattern
    5. Builder Pattern.
  • Structural Design Pattern
    1. Adapter Pattern
    2. Bridge Pattern
    3. Composite Pattern
    4. Decorator Pattern
    5. Facade Pattern
    6. Flyweight Pattern
    7. Proxy Pattern
  • Behavioral Design Pattern
    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

Creational design patterns are used when creating objects.





What is 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.

These authors are collectively known as Gang of Four (GOF).

Design patterns are based on the following principles of object orientated design.

  • Program to an interface not an implementation

  • Favor object composition over inheritance