Article series

A singleton of javascript design patterns

Adapter pattern for javascript design pattern

Decorator pattern for javascript design pattern

Javascript design pattern proxy pattern

Comparison of javascript adaptation, proxy, and decorator patterns

Javascript design pattern state pattern

Iterator pattern for javascript design pattern

Javascript design pattern strategy pattern

Javascript design pattern observer pattern

Publish subscriber pattern for javascript design pattern

Adapter pattern: Converts the interface (method or property) of one class (object) into another interface (method or property) that the customer expects, so that classes (object) that would otherwise not work together due to incompatible interfaces can work together. Simply put, it is a “converter” designed for compatibility.

Proxy mode: the user has no right to access the target object, and proxy is added in the middle to do authorization and control through proxy

The Decorator pattern, also known as the decorator pattern, allows you to add responsibilities to objects dynamically during program execution without changing the objects themselves. Compared with inheritance, decorator is a more portable and flexible practice.

Adaptor: Compatible, does not process the request, directly to the new method, the new method can be different from the original method name. For example, compatible interface requests, the old Ajax successfully ADAPTS to the new FETCH request; There is also compatible event handling between different browsers

Proxy: is characterized by isolation. To access the ontology, you must first access the proxy object, which plays a protective role. Controls access to ontology objects. The proxy provides the same method advocacy as the ontology method name, such as preloading, and broker/star stuff

Decorator: Features enhancements that add functionality to an object multiple times (such as printing a log and adding a method description) to form a decorator chain, while the adapter or agent wraps the original object only once. For example, React higher-order components

Decorator mode is “add behavior,” proxy mode is “control access behavior,” and adapter mode is “transform behavior.”

The proxy pattern may have processing and then call the ontology. Adapter mode, on the other hand, passes directly to the original method. Here’s an example:

“Agent mode” (Yan Father) : The school fees 1000 yuan, so much? “Adapter mode” (mother) : the school fees to 1000 pieces, to give to.