Node.js Design Patterns

This repository contains examples and implementations of various design patterns in Node.js. The design patterns are organized into three main categories: Behavioral, Creational, and Structural patterns. Each pattern is demonstrated with code examples to help you understand their usage and benefits.

Table of Contents

  1. Behavioral Patterns
  2. Creational Patterns
  3. Structural Patterns

Behavioral Patterns

Chain of Responsibility Pattern

  • The Chain of Responsibility pattern is used to pass a request along a chain of handlers. Each handler can either process the request or pass it to the next handler in the chain.

Command Pattern

  • The Command pattern encapsulates a request as an object, thereby allowing for parameterization of clients with queues, requests, and operations.

Iterator Pattern

  • The Iterator pattern provides a way to access the elements of an aggregate object sequentially without exposing its underlying representation.

Observer Pattern

  • The Observer pattern defines a one-to-many dependency between objects so that when one object changes state, all its dependents are notified and updated automatically.

Strategy Pattern

  • The Strategy pattern defines a family of algorithms, encapsulates each one, and makes them interchangeable. This allows the algorithm to vary independently from the clients that use it.

Creational Patterns

Builder Pattern

  • The Builder pattern separates the construction of a complex object from its representation, allowing the same construction process to create different representations.

Factory Pattern

  • The Factory pattern defines an interface for creating an object but allows subclasses to alter the type of objects that will be created.

Prototype Pattern

  • The Prototype pattern is used to create a duplicate object or clone of the current object to avoid the expensive cost of creating a new instance.

Singleton Pattern

  • The Singleton pattern ensures that a class has only one instance and provides a global point of access to it.

Structural Patterns

Adapter Pattern

  • The Adapter pattern allows the interface of an existing class to be used as another interface. It is often used to make existing classes work with others without modifying their source code.

Composite Pattern

  • The Composite pattern allows you to compose objects into tree structures to represent part-whole hierarchies. It lets clients treat individual objects and compositions of objects uniformly.

Decorator Pattern

  • The Decorator pattern attaches additional responsibilities to an object dynamically. Decorators provide a flexible alternative to subclassing for extending functionality.

Proxy Pattern

  • The Proxy pattern provides a surrogate or placeholder for another object to control access to it.

Acknowledgements

This repository is inspired by the design patterns described in various software engineering resources.