/js-patterns

Some common design patterns using JavaScript

Primary LanguageJavaScriptMIT LicenseMIT

Design Patterns using JavaScript

Some common design patterns using JavaScript

As per Wikipedia:

In software engineering, a design pattern is a general reusable solution to a commonly occurring problem within a given context in software design. A design pattern is not a finished design that can be transformed directly into source or machine code. It is a description or template for how to solve a problem that can be used in many different situations. Patterns are formalized best practices that the programmer must implement themselves in the application.[1] Object-oriented design patterns typically show relationships and interactions between classes or objects, without specifying the final application classes or objects that are involved. Patterns that imply object-orientation or more generally mutable state, are not as applicable in functional programming languages.

There are three types of Design Patterns as per GOF:

  • Creational Design Patterns

Creational patterns are used to create objects of the right class for a problem, generally when instances of several different classes are available. They're particularly useful when you are taking advantage of polymorphism and need to choose between different classes at runtime rather than compile time.

  • Structural patterns

Structural patterns form larger structures from individual parts, generally of different classes. Structural patterns vary a great deal depending on what sort of structure is being created for what purpose.

  • Behavioral patterns

Behavioral patterns describe interactions between objects. They focus on how objects communicate with each other. They can reduce complex flow charts to mere interconnections between objects of various classes. Behavioral patterns are also used to make the algorithm that a class uses simply another parameter that's adjustable at runtime.

We covered the following patterns here:

  • command pattern - Behavioral
  • constructor pattern - Creational
  • decorator pattern - Structural
  • facade pattern - Structural
  • factory pattern - Creational
  • flyweight pattern - Structural
  • mediator pattern - Behavioral
  • mixin pattern - Creational
  • module pattern - Creational
  • observer pattern - Behavioral
  • prototype pattern - Creational
  • revealing module pattern - Creational
  • singleton pattern - Creational
  • strategy pattern - Behavioral