MadhushaPrasad / javascript-design-patterns

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

JavaScript Design Patterns

Design patterns provide established solutions to common problems in software design. These solutions are templates for writing code to address specific scenarios or challenges. In the JavaScript context, several design patterns are commonly utilized.

Table of Contents

Creational Patterns

  • Factory Pattern: Used to create objects without specifying the exact class of the object being created.
  • Singleton Pattern: Ensures a class has only one instance and provides a global point of access to it.
  • Prototype Pattern: Uses cloning or copying of existing objects instead of creating new ones.
  • Builder Pattern: Separates the construction of a complex object from its representation.
  • Object Pool Pattern: Reuses and shares objects that are expensive to create.

Structural Patterns

  • Adapter Pattern: Allows objects with incompatible interfaces to collaborate.
  • Decorator Pattern: Dynamically attaches additional responsibilities to an object.
  • Composite Pattern: Uses tree structures to represent part-whole hierarchies.
  • Proxy Pattern: Provides a placeholder to control access to another object.
  • Facade Pattern: Offers a simplified interface to a more complex body of code.
  • Flyweight Pattern: Shares as much data as possible with similar objects to minimize memory usage.
  • Bridge Pattern: Decouples an abstraction from its implementation, allowing variation.

Behavioral Patterns

  • Command Pattern: Encapsulates a command request as an object.
  • Observer Pattern: Implements a subscription mechanism to notify multiple objects about events.
  • Iterator Pattern: Provides sequential access to elements without exposing the underlying representation.
  • Strategy Pattern: Defines interchangeable algorithms.
  • State Pattern: Allows an object to change its behavior when its internal state changes.
  • Template Pattern: Defines an algorithm's structure but defers some steps to subclasses.
  • Mediator Pattern: Minimizes direct communication between classes by introducing a mediator.
  • Chain of Responsibility Pattern: Decouples the sender of a request from its receiver.
  • Memento Pattern: Captures and externalizes an object's state to restore it later.
  • Visitor Pattern: Introduces new operations to objects without modifying them.

Concurrency Patterns

  • Promises: Represents asynchronous operations.
  • Callback Pattern: Uses a function passed as an argument to another function, invoked after an operation's completion.

Architectural Patterns

  • Module Pattern: Isolates parts of an application to create modular code.
  • Revealing Module Pattern: Improves the module pattern by revealing only desired functionality.
  • MVC (Model-View-Controller): Divides an application into three interconnected components.

Other Patterns

  • Middleware Pattern: Executes functions in sequence for every request, common in web server frameworks.
  • Dependency Injection: Provides an object with its dependencies from outside.

Note: Design patterns provide a guideline and template to address challenges. It's essential to understand the problems they resolve and apply them judiciously without forcing patterns where they aren't needed.

About


Languages

Language:JavaScript 100.0%