Design Patterns

Introduction

  • Gang of Four (GoF) is a term referring to a group of 4 authors (Erich Gamma, Richard Helm, Ralph Johnson and John Vlissides) who published the classic book Design Patterns: Elements of Reusable Object-Oriented Software in 1994. The book summarizes 23 design patterns commonly used to solve recurring object-oriented programming (OOP) design problems.
  • The main benefit of GoF Design Patterns is providing standardized solutions to common problems, making source code easier to maintain, extend and creating a common language for developers when discussing software architecture.
alt text

These 23 design patterns are divided into 3 main groups:

Creational Patterns

  • Factory Method: Defines an interface for creating an object, but lets subclasses decide which class to instantiate.
  • Abstract Factory: Provides an interface for creating 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 different representations.
  • Prototype: Creates new objects by cloning an existing prototype object instead of creating them from scratch.
  • Singleton: Ensures a class has only one instance throughout the application lifecycle and provides a global point of access to it.

Structural Patterns

  • Adapter: Converts the interface of a class into another interface expected by the client, allowing classes with incompatible interfaces to work together.
  • Bridge: Decouples an abstraction from its implementation so that the two can vary independently.
  • Composite: Composes objects into tree structures to represent part-whole hierarchies, allowing clients to treat individual objects and compositions of objects uniformly.
  • Decorator: Attaches additional responsibilities to an object dynamically at runtime without altering the structure of the original class.
  • Facade: Provides a simplified interface to a set of complex interfaces in a subsystem.
  • Flyweight: Optimizes memory usage by sharing as much common data as possible among multiple similar objects instead of storing data individually.
  • Proxy: Provides a surrogate or placeholder object to control access to another object.

Behavioral Patterns

  • Chain of Responsibility: Passes a request along a chain of handler objects, where each handler decides whether to process the request or pass it to the next handler.
  • Command: Encapsulates a request as an object, allowing parameterization of operations, queuing of requests and support for undo operations.
  • Interpreter: Defines a grammatical representation for a specific language and provides an interpreter to process sentences in that language.
  • Iterator: Provides a way to access the elements of an aggregate object sequentially without exposing its underlying representation.
  • Mediator: Defines an object that encapsulates how a set of objects interact, reducing direct dependencies between them.
  • Memento: Captures and externalizes an object's internal state so that it can be restored later without violating encapsulation.
  • Observer: Defines a one-to-many dependency between objects so that when one object changes state, all its dependents are notified and updated automatically.
  • State: Allows an object to alter its behavior when its internal state changes.
  • Strategy: Defines a family of algorithms, encapsulates each one and makes them interchangeable at runtime.
  • Template Method: Defines the skeleton of an algorithm in a base class, allowing subclasses to override specific steps without changing the algorithm structure.
  • Visitor: Separates an algorithm from an object structure on which it operates, allowing new operations to be added to existing object structures without modifying them.

Happy coding!

See more articles here.

Comments

Popular posts from this blog

All Practice Series

Understanding React Server Component

Kubernetes Deployment for Zero Downtime

Sitemap

Deploying a NodeJS Server on Google Kubernetes Engine

React Practice Series

Docker Practice Series

A Handy Guide to Using Dynamic Import in JavaScript

Setting up Kubernetes Dashboard with Kind

Helm for beginer - Deploy nginx to Google Kubernetes Engine