Prototype/Class Patternmore_vert

Addy Osmani's Explanation

Prototype/Class Patternclose

Allows us to define a blueprint for a specific type of item and then reuse it by creating a new object from that class. Alternative: specify the kinds of objects to create using a prototypical instance, and create new objects from the 'skeleton' of an existing object, thus boosting performance and keeping memory footprints to a minimum.

Constructor/Builder Patternmore_vert

Addy Osmani's Explanation

Prototype/Class Patternclose

The constructor pattern is one step further from the class pattern, where we leverage a class created to initiate a new extended class from it. Alternative: Object constructors are used to create specific types of objects — both preparing the object for use and accepting arguments which a constructor can use to set the values of member properties and methods when the object is first created.

Singleton Patternmore_vert

Addy Osmani's Explanation

Singleton Patternclose

Singleton pattern simply prevents our class from creating more than one instance of the blueprint we defined. Alternative: The Singleton pattern is thus known because it restricts instantiation of a class to a single object. Classically, the Singleton pattern can be implemented by creating a class with a method that creates a new instance of the class if one doesn’t exist. In the event of an instance already existing, it simply returns a reference to that object.

Factory Patternmore_vert

Addy Osmani's Explanation

Factory Patternclose

Factory pattern is great when you want to create a mechanism to create other objects. This can be useful when you want a factory to handle most of your classes and then simply use this factory method to create new objects. Alternative: The Factory pattern is another creational pattern concerned with the notion of creating objects. Where it differs from the other patterns in its category is that it doesn’t explicitly require the use of a constructor. Instead, a Factory can provide a generic interface for creating objects, where we can specify the type of factory object we wish to be created.

Abstract Factory Patternmore_vert

Addy Osmani's Explanation

Abstract Factory Patternclose

The Abstract Factory pattern allows you abstract factories themselves and enables you to create multiple factories, classes etc. Alternative: Abstract Factory pattern aims to encapsulate a group of individual factories with a common goal. It separates the details of implementation of a set of objects from their general usage.