# 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.

{% hint style="info" %}
**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.
{% endhint %}

## 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 <mark style="background-color:red;">23</mark> 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.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://www.pranaypourkar.co.in/the-programmers-guide/system-design/design-principles-and-patterns/design-pattern.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
