Introduction to design patterns in JS

  • |
  • 06 April 2022

Design patterns are general reusable solutions to common problems in software design that software engineers face during software development. It represents the best practices obtained over substantial period of time used by experienced object-oriented developers.

Usage of design patterns

Design patterns are toolkit. Toolkit that can speed up the development process by providing proven development paradigms. They teach how to solve all sort of problems using principles of object-oriented design. Reusing design patterns helps to prevent subtle issues that can cause major problems and improves code readability for developers familiar with the patterns.
Every pattern is specific to particular scenario. They define a well-known and understood names that you and your teammates can use to communicate more efficiently. For example singleton pattern signifies use of single object and we can tell each other that program is following a singleton pattern.

Classification of patterns

The most basic and low-level patterns are often called idioms. They usually apply onto a single programming language.

The most universal and high-level patterns are architectural patterns. Developers can implement these patterns almost in any programming language.

Design patterns had been categorized by their intent, or purpose into three classification based on what kind of problem they solve:

Creational design patterns

They deal with object creation mechanisms that increase flexibility and reuse of existing code.

Creational design patterns are for example: abstract factory, factory method, builder or singleton.

Structural design patterns

Explains how to assemble objects and classes into larger structures, while keeping these structures flexible and efficient. They identify a simple way to realize relationships among entities.

Examples of structural patterns are: adapter, bridge, composite, decorator.

Behavioral design patterns

These patterns are all about communication between objects.

Examples of this type include: chain of responsibility, command, iterator or mediator.

You May Also Like