Design Pattern

About Design patterns

A pattern is a reusable solution that can be applied to commonly occurring problems without the need to code a completely unique solutions each and every time. Design patterns are recurring solutions to common problems encountered in software design. They represent best practices and proven solutions to specific design problems. These patterns are not specific to a particular domain, technology, or programming language instead, they are applicable across various contexts.

Design patterns provide a structured and reusable approach to solving problems, allowing developers to leverage the experience of others and build upon well-established solutions. They help in improving code readability, maintainability, and scalability by promoting modular, flexible, and extensible designs.

Gang of Four (GOF) in Design Patterns

Gang of Four (GOF) are the 4 superheroes who invented the concept of design patterns. These heroes are Erich Gamma, Ralph Johnson, Richard Hel and John Vlissides. These people documented the design patterns in a book called “Design Patterns: Elements of Reusable Object-Oriented Software” in 1995. If not for these people, the software developers would have wasted time-solving problems of recurring nature instead of focussing on business requirements.

Advantages of Java Design Patterns

Design patterns are template-based reusable solutions to help developers work effortlessly in multiple projects. In Java, the design patterns are flexible and help to identify unwanted repetitive code easily. The architecture of the software can be customised as per the requirements. Some of the advantages of using design patterns in Java are:

  • They are reusable and can be used in multiple projects.

  • They provide template solutions for defining system architecture.

  • They provide transparency to software design.

  • They are well-tested and proven means of developing robust solutions effortlessly

Types of Design Patterns

As per the design pattern reference book Design Patterns - Elements of Reusable Object-Oriented Software , there are 23 design patterns which can be classified in three categories:

  • Creational Pattern

These patterns deal with object creation mechanisms, trying to create objects in a manner suitable to the situation. Examples include Singleton, Factory Method, Abstract Factory, Builder, etc.

  • Structural Pattern

These patterns deal with object composition or structure, focusing on how classes and objects are composed to form larger structures. Examples include Adapter, Bridge, Composite, Decorator, Facade, Proxy, etc.

  • Behavioral Pattern

These patterns deal with object interaction, defining how objects communicate and behave with each other. Examples include Observer, Strategy, Chain of Responsibility, Command, Iterator, State, Template Method, Visitor, etc.

Last updated