Design Patterns Tutorial in Java

Design Patterns Tutorial in Java

Design Patterns in Java

A design pattern is a reusable generic solution to a frequent problem in software design. Design patterns are recommended practices that experienced developers employ to overcome common challenges.

Knowing merely principles such as inheritance, polymorphism, and encapsulation will not qualify you as an excellent object oriented developer. You must consider developing reusable, adaptable, and simple-to-maintain systems. To handle certain common design difficulties, you need be familiar with at least a few design patterns.

Types of Design Patterns

Design patterns can be broadly classified in three categories: Creational, Structural and Behavioral design patterns.

  • Creational Patterns : These design patterns deal with the problem of creating object while hiding the logic and complexity associated with it. Singleton Pattern, Factory Pattern, Builder Pattern etc comes under creational design patterns.

  • Structural Patterns : These design patterns are used to define relationship between classes, objects and various entities. Adapter Pattern, Bridge Pattern, Proxy Pattern etc comes under structural design patterns.

  • Behavioral Patterns : These design patterns deal with communication between objects. Command Pattern, Mediator Pattern, Observer Pattern, Strategy Pattern etc comes under behavioral patterns.

Creational Design Pattern
Factory Design Pattern
Factory Design Pattern in Java
Abstract Factory Design Pattern
Abstract Factory Design Pattern in Java
Prototype Design Pattern
Prototype Design Pattern in java
Singleton Design Pattern
Singleton Design Pattern in Java
Builder Design Pattern
Builder Design Pattern in java
Structural Design Patterns
Adapter Design Pattern
Adapter Design Pattern in Java
Bridge Design Pattern
Bridge Design Pattern in Java
Filter Design Pattern
Filter Design Pattern in Java
Composite Design Pattern
Composite Design Pattern in Java
Decorator Design Pattern
Decorator Design Pattern in Java
Facade Design Pattern
Facade Design Pattern in Java
Flyweight Design Pattern
Flyweight Design Pattern in Java
Iterator Design Pattern
Iterator Design Pattern in Java
Proxy Design Pattern
Proxy Design Pattern in Java
Behavioral Design Patterns
Command Design Pattern
Command Design Pattern in Java
Interpreter Design Pattern
Interpreter Design Pattern in Java
Observer Design Pattern
Observer Design Pattern in Java
State Design Pattern
State Design Pattern in Java
Strategy Design Pattern
Strategy Design Pattern in Java
Memento Design Pattern
Memento Design Pattern in Java
Mediator Design Pattern
Mediator Design Pattern in Java
Template Design Pattern
Template Design Pattern in Java
Chain of Responsibility Pattern
Chain of Responsibility Pattern in Java

Principles of Design Patterns

  • Identify the components of your system that varies and keep them separate from what remains the same. In this way, you can change or extend the components that vary independently without affecting the components that remains same.
  • Program to an interface not an implementation.
  • Favour composition over inheritance. In other words, a "HAS-A relationship is better than IS-A".

Advantages of Design Patterns

  • Design Patterns helps you to build reusable systems with good object oriented design qualities.
  • They capture the proven object oriented experiences. You don't have to re-invent again.
  • It provides shared vocabularies that allows you to say more with less. It helps developers to communicate efficiently.
  • Design patterns let you write better code more quickly.
  • It specifies the best practices and solutions used the developers everywhere to solve a particular problems faced during software development.
Important Points About Design Patterns
  • Patterns are not invented, they are discovered over time by experienced developers.
  • Design pattern won't give you code or guarantee an absolute solution. It is a general solution of a commonly occurring problem that can be used in many different situations.
  • Standard Libraries and frameworks are not design patterns. They are the implementations of design patterns.
  • Most design patterns helps us to extend and vary components of a system independently of each other.