Creational Design Patterns: Singleton Pattern

Singleton mode
1. As an object creation mode, the singleton mode ensures that there is only one instance of a certain class, and instantiates itself and provides this instance to the entire system. This class is called a singleton class.

2. The characteristics of the singleton pattern:
    a singleton class can only have one instance.
    A singleton class must create its own unique instance by itself.
    A singleton class must provide this instance to all other objects.

3. The singleton mode is divided into lazy type and hungry type. The
    lazy type: the instance is not initialized;
    the hungry type: the instance is initialized;

4. According to the statement in "Efficient Java Second Edition": the
    single-element enumeration type has become the implementation of Singleton the best method. Implementing a singleton with an enumeration is as simple as writing an enumeration type that contains a single element.

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=327028803&siteId=291194637