Currently, the singleton mode is not fully implemented using static functions.
1. Ease of use: If Initialization is required, the singleton mode can be completed in the constructor. the class of all static functions requires an additional function to complete initialization.
If you call this initialize function, there will be problems in subsequent operations. The constructor will be called by default, so it is easy to use and has made the least assumptions for the user.
2. Initialization time: the singleton mode is flexible in initialization and can be initialized as needed. Full static functions will inevitably lead to all static members, and static members will be initialized at compilation. If
Initialization is expensive andProgramThis class may not be used in it, which will be a great advantage of the singleton mode. By the way, the initialization sequence of global variables is not specified.
For example, the global variable int A; int B; does the compiler initialize a first or B first? I think you can only guess, or experiment with a compiler to give the answer. What will happen if there is a new compiler?
3. The most important difference is that the singleton mode can be polymorphism, while the fully static classes cannot support polymorphism.
Currently, the singleton mode is not fully implemented using static functions.
1. Ease of use: If Initialization is required, the singleton mode can be completed in the constructor. the class of all static functions requires an additional function to complete initialization.
If you call this initialize function, there will be problems in subsequent operations. The constructor will be called by default, so it is easy to use and has made the least assumptions for the user.
2. Initialization time: the singleton mode is flexible in initialization and can be initialized as needed. Full static functions will inevitably lead to all static members, and static members will be initialized at compilation. If
Initialization costs are relatively expensive, and the class may not be used in the program, which is a great advantage of the singleton mode. By the way, the initialization sequence of global variables is not specified.
For example, the global variable int A; int B; does the compiler initialize a first or B first? I think you can only guess, or experiment with a compiler to give the answer. What will happen if there is a new compiler?
3. The most important difference is that the singleton mode can be polymorphism, while the fully static classes cannot support polymorphism.