YDundie / desing-patterns

desing-patterns

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

JavaScript Design Patterns

This repository demonstrates various design patterns implemented in JavaScript. The design patterns covered in this repository are:

Adapter

The Adapter pattern allows objects with incompatible interfaces to work together. It acts as a bridge between two incompatible interfaces, converting the interface of one object into another interface that clients expect. This pattern is useful when integrating legacy code or third-party libraries into a new system.

Builder

The Builder pattern is used to create complex objects step by step. It separates the construction of an object from its representation, allowing different representations of the same object to be created. This pattern is useful when you need to create objects with many optional parameters or when you want to decouple the construction of an object from its final representation.

Factory

The Factory pattern is a creational pattern that provides an interface for creating objects in a super class, but allows subclasses to alter the type of objects that will be created. It encapsulates the object creation logic and allows the client to create objects without specifying their concrete classes. This pattern is useful when you want to delegate the responsibility of object creation to subclasses or when you need to decouple object creation from the client code.

Observer

The Observer pattern allows objects to subscribe and receive notifications about changes in the state of another object. It establishes a one-to-many relationship between objects, where changes in one object are automatically propagated to its subscribers. This pattern is useful when you want to achieve loose coupling between objects and enable them to react to changes in the state of other objects.

Singleton

The Singleton pattern ensures that a class has only one instance and provides a global point of access to that instance. It restricts the instantiation of a class to a single instance and provides a way to access that instance throughout the application. This pattern is useful when you need to have a single instance of a class that coordinates actions across the system or when you want to control access to a shared resource.

Strategy

The Strategy pattern allows objects to dynamically change their behavior at runtime by encapsulating different strategies or algorithms in separate classes. It enables the client to select a strategy or algorithm at runtime, without changing the object's interface. This pattern is useful when you have different algorithms or strategies that need to be interchangeable or when you want to decouple the behavior of an object from its implementation.

Usage

Each design pattern is implemented in a separate folder in this repository. You can navigate to each folder to see the implementation details and usage examples of the design pattern in JavaScript. You can also run the provided examples to see the patterns in action.

Contributing

If you would like to contribute to this repository, feel free to submit a pull request. Please make sure to follow the coding conventions and provide proper documentation for any changes or additions.

About

desing-patterns


Languages

Language:JavaScript 100.0%