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.
- 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.
- The Command pattern encapsulates a request as an object, thereby allowing for parameterization of clients with queues, requests, and operations.
- The Iterator pattern provides a way to access the elements of an aggregate object sequentially without exposing its underlying representation.
- 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.
- 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.
- The Builder pattern separates the construction of a complex object from its representation, allowing the same construction process to create different representations.
- The Factory pattern defines an interface for creating an object but allows subclasses to alter the type of objects that will be created.
- 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.
- The Singleton pattern ensures that a class has only one instance and provides a global point of access to it.
- 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.
- 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.
- The Decorator pattern attaches additional responsibilities to an object dynamically. Decorators provide a flexible alternative to subclassing for extending functionality.
- The Proxy pattern provides a surrogate or placeholder for another object to control access to it.
This repository is inspired by the design patterns described in various software engineering resources.