Design patterns are solution to a commonly occurring pattern that is generally agreed on as the best solution.
In ECMAScript 2015 classes were added as syntactical sugar over the existing prototype-based inheritance.
The module pattern is used to encapsulate a group of methods that belong to the same family.
A factory simplifies the creation of an object. The factory pattern is helpful when creating an object becomes complex and requires different versions of the object depending on the context.
The singleton pattern is used to restrict an object to just a single instance across your application. When called it remembers the last time it was called and returns the s
The facade pattern is used to provide a simple interface or API to an otherwise complex sub system. When you look at the front of a building, you’re looking at a facade. The building’s facade hides all the potential complexity inside the building.
React is a common example of a facade. The complexity of managing a virtual DOM is hidden behind an easy to use interface in the components class.
The flyweight pattern is used when dealing with large sets of objects. The pattern conserves memory by sharing portions of objects with other objects in the set.
The flyweight finds duplicate properties, creates a unique reference to each unique property and swaps the property out on the data set for the unique reference. This makes each property unique, reducing the side of the data set.
The observer pattern defined a one-to-many relationship between an observable and its’s subscribers. The subscribers are responsible for subscribing and unsubscribing to the observable while the observable it’self is responsible for pushing updates to the subscribers.
The observable comes with three core methods, subscribe, unsubscribe and broadcast. The subscribe method is called with the subscriber as a parameter, adding it to it’s list of subscribers while the subscribe method removes the subscriber from the observable’ list of subscribers.
Still to come: