Search This Blog

2023/08/30

Design Patterns: Types


A design pattern is a reusable and general solution to a common software design
problem.It represents a blueprint for solving a particular class of problems in
a consistent and efficient manner. Design patterns provide a shared vocabulary
and a set of proven practices that enable software developers to communicate
more effectively, design robust and maintainable code, and avoid reinventing the
wheel for common challenges.

Design patterns capture the collective experience and expertise of software
designers and architects, offering solutions to recurring issues in software
design, such as structuring classes and objects, managing relationships between
components, and handling interactions between different parts of a system. They
help promote code that is modular, flexible, and easier to extend or modify over
time.

Design patterns are not code snippets or ready-made solutions that can be
directly copied into a project. Instead, they provide high-level descriptions of
the problem, the solution, and the context in which the pattern should be
applied. Developers need to adapt and implement the patterns according to the
specific requirements of their projects.


Design patterns are divided into three main categories:
creational, structural,and behavioral. Each category addresses a different
aspect of software design and helps solve specific design problems.

Here's a brief overview of the types of design patterns within each category:

Creational Design Patterns:
These patterns focus on object creation mechanisms, attempting to create objects
in a manner that suits the situation. Creational patterns provide control over
object instantiation.

Singleton: Ensures a class has only one instance and provides a global point of
access to that instance.

Factory Method: Creates objects without specifying the exact class of object
that will be created.

Abstract Factory: Creates families of related or dependent objects without
specifying their concrete classes.

Builder: Separates the construction of a complex object from its
representation, allowing the same construction process to create various
representations.

Prototype: Creates new objects by copying an existing instance, known as the
prototype.

Structural Design Patterns:
These patterns deal with object composition, creating relationships between
objects to form larger structures. Structural patterns provide ways to define
relationships between objects.

Adapter: Converts the interface of a class into another interface that clients
expect.

Bridge: Separates abstraction from its implementation, allowing both to evolve independently.

Composite: Composes objects into tree structures to represent part-whole
hierarchies.

Decorator: Adds behavior or responsibilities to individual objects dynamically,
without affecting other objects.

Facade: Provides a unified interface to a set of interfaces in a subsystem.

Flyweight: Shares objects to reduce memory consumption by allowing objects to
be reused instead of recreated.

Proxy: Provides a surrogate or placeholder for another object to control
access to it.

Behavioral Design Patterns:
These patterns deal with object collaboration and responsibilities, focusing
on how objects interact and communicate with each other. Behavioral patterns
provide solutions for object interaction and responsibilities.

Chain of Responsibility: Allows an object to pass a request along a chain of
potential handlers.

Command: Encapsulates a request as an object, allowing parameterization of
clients with different requests, queuing, and logging of requests.

Interpreter: Provides a way to evaluate language grammar or expressions.

Iterator: Provides a way to access elements of a collection sequentially
without exposing its underlying representation.

Mediator: Reduces the coupling between components by allowing them to
communicate through a central mediator.

Memento: Captures an object's internal state to be restored later, without
exposing its internal structure.

Observer: Defines a dependency between objects so that when one object changes
state, all its dependents are notified and updated automatically.

State: Allows an object to change its behavior when its internal state changes.

Strategy: Defines a family of algorithms, encapsulates each one, and makes
them interchangeable.

Template Method: Defines the structure of an algorithm in the base class but
lets subclasses override specific steps.

Visitor: Lets you add further operations to objects without having to modify
them.

Each design pattern is a valuable tool in a programmer's toolbox, offering
standardized solutions to common design problems and promoting software
that's easier to understand, maintain, and scale.

No comments:

Post a Comment