Single-Case mode

Source: Internet
Author: User

single-case mode (Singleton)

    1. limits the The number of instantiations can only be once ; (If the instance does not exist, a new instance is created; If the instance exists, a reference to that instance is returned)

    2. In JavaScript, Singleton acts as a shared resource namespace, isolating code implementations from the global namespace, providing a single point of access for functions. --"JavaScript design pattern P39" (in the 1th Point of explanation)

Applicability of a single case model

    1. When a class can have only one instance and the customer can access it from a well-known access point;

    2. the only instance should be the subclass extensible, and the customer should be able to use an extended instance without changing the code. --"JavaScript design mode P40"


    1. Only one time is instantiated;

    2. Save memory.


    1. The modules in the system appear or are tightly coupled;

    2. Or its logic is too scattered;

    3. It is difficult to create multiple instances;

    4. testing can be difficult;

    5. ~ ~ And so on.


    1. Don't overdo it.

Application Scenarios:

    1. the system does just one object to coordinate other objects time. (e.g. use in communication coordination)


    • Lab 1:

    • ~ ~ to be added

Learning materials:

    1. the JavaScript design model;

    2. Uncle Tom understands the JavaScript series in depth.

Single-Case mode

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: 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.