Design Patterns

Design Patterns

Design Patterns are typical solutions to common problems in software design. Each pattern is like a blueprint that you can customize to solve a particular design problem in your code.

Total of 23 design patterns are present. Grouping of Design Patterns:

  • Behavioral pattern (11): These patterns focus on object interaction and communication, describing how objects collaborate to achieve specific tasks.
  • Structural pattern (7): These patterns deal with how classes and objects are composed to form larger structures, focusing on relationships and compositions.
  • Creational patterns (5): These patterns focus on object creation mechanisms, providing ways to create objects in a flexible and efficient manner.

Behavioral Design Pattern

NameDescriptionImageCode
Chain of ResponsibilityAvoids coupling the sender of a request to its receiver by giving multiple objects a chance to handle the request.
CommandEncapsulates a request as an object, thereby allowing for parameterization of clients with different requests, queueing of requests, and un-doable operations.
InterpreterDefines a representation for a grammar along with an interpreter that uses the representation to interpret sentences in the language.
IteratorProvides a way to access the elements of an aggregate object sequentially without exposing its underlying representation.
MediatorDefines an object that encapsulates how a set of objects interact.
MementoWithout violating encapsulation, captures and externalizes an object's internal state so that the object can be restored to this state later.
ObserverDefines a one-to-many dependency between objects so that when one object changes state, all its dependents are notified and updated automatically.
StateAllows an object to alter its behavior when its internal state changes.
StrategyDefines a family of algorithms, encapsulates each one, and makes them interchangeable.
Template MethodDefines the skeleton of an algorithm in an operation, deferring some steps to subclasses.
VisitorRepresents an operation to be performed on the elements of an object structure.

Structural Design Pattern

NameDescriptionImageCode
AdapterConverts the interface of a class into another interface clients expect.
BridgeSeparates an abstraction from its implementation so that the two can vary independently.
CompositeComposes objects into tree structures to represent part-whole hierarchies.
DecoratorDynamically adds responsibilities to an object.
FacadeProvides a simplified interface to a complex system of classes.
FlyweightUses sharing to support a large number of fine-grained objects efficiently.
ProxyProvides a surrogate or placeholder for another object to control access to it.

Creational Design Pattern

NameDescriptionImageCode
SingletonEnsures a class has only one instance and provides a global point of access to it.Code
Factory MethodDefines an interface for creating objects, but lets subclasses decide which class to instantiate.Code
Abstract FactoryProvides an interface for creating families of related or dependent objects without specifying their concrete classes.Code
BuilderSeparates the construction of a complex object from its representation.Code
PrototypeSpecifies the kind of objects to create using a prototypical instance and creates new objects by cloning this prototype.Code

Todo

  • Behavioral - Interpreter
  • Add Image ad code to the tables