A simple understanding of JavaScript design Patterns

Source: Internet
Author: User

Design patterns can be understood as a series of code frameworks, which I think primarily involves encapsulation concepts. The code snippet that realizes a certain function is encapsulated in the function, it can be conveniently called, at the same time facilitates the reuse of the code, and improves the maintainability of the code. The following is a brief introduction to several design patterns of personal feelings.

1. Single-case mode

Similar to a class with only one object instance. Suppose an item belongs to only one person.

2. Constructor mode

Similar to the constructor in C, you can create a specific type of object, and then you can declare different variables and member functions in the object, and you can have different parameters. Like I want to be a stool, I can make a common stool, have a long and wide height and other properties and functions can be done, in addition I can also make a higher level, such as a stool with a backrest, as well as the function of lying down and so on.

3. Builder's Model

Separating complex objects from their representations allows the same build process to create different representations. Similar to building a house, customers just need to give the desired house general function and style, and then by the designer in the middle, guide the implementation of concrete implementation. It can be understood that the complex objects are gradually disassembled into specific small objects, and then implemented and assembled to achieve complex objects, whether a bit similar to the partition algorithm.

4. Factory mode

Defines an interface for creating objects, which subclasses decide which class to instantiate, while subclasses can override interface methods to specify their own object types (complex factories), or they can, without rewriting, return different objects directly to different environments (simple factories).

5. Proxy mode

Provides a proxy for other objects to control access to this object. A position that is similar to an intermediary, coordinates the interaction between two objects, or acts directly as an authorized person of a party, dealing with something in its sole discretion.

6. Command mode

Used to parameterize and transfer method calls, which can be performed at any time when needed. The call, request, and operation of the function are encapsulated into a single object, and then a series of processing is performed on the object. A similar chairman gave orders to the general manager, and then the general manager assigned specific tasks to the following people.

Initial exposure to design patterns, understanding may be a bit biased, further understanding of the need to slowly pondering later.

A simple understanding of JavaScript design Patterns

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.