What are Design Patterns
Design patterns are tested and well-established solutions to commonly occurring software development problems. They are not tied to JavaScript specifically. They are reusable designs to these commonly occurring problems. Each design pattern has a name and we categorize them into three main categories:
Creational Patterns
Creational patterns are all about object creation. Some well known creational patterns are:
- Prototype: Lets you create copies of an object by cloning them, without depending on their classes.
- Singleton: Ensures that a class has only one instance at any given time and provides global access to it.
- Builder: Lets you construct complex objects, with the flexibility to produce different representations using the same construction mode.
Structural Patterns
Structural patterns are about finding ways to describe the relationship between different entities while keeping them flexible and efficient. Some commonly used structural patterns are:
- Decorator: decorate your classes and objects with new behaviors by simply wrapping them into special functions.
- Facade: create a simplified interface to an existing library or framework to ease their usage for common tasks.
- Proxy: It creates an interface to another object, allowing you to perform certain tasks before or after accessing the object.
- Composite: compose objects into a tree structure where every object in the tree has the same interface.
Behavioral Patterns
Behavioral patterns aim to solve communication problems between objects. They tend to improve flexibility and decoupling. Some more well known behavioral patterns are:
- PubSub: It creates publishers and subscribers, where each subscriber can listen to publishers, and publishers can notify subscribers about changes in your objects.
- Memento: Let's you save and then later restore the previous state of your objects.
- Command: Let's you encapsulate the information necessary to perform various parameterized actions.
Rocket Launch Your Career
Speed up your learning progress with our mentorship program. Join as a mentee to unlock the full potential of Webtips and get a personalized learning experience by experts to master the following frontend technologies: