(According to the msdn webcast courses)
Mode classification:
Purpose:
Creational: Responsible for object Creation
Structural: A combination of processing classes and objects.
Behavioral: Responsibility Assignment in class-object interaction
In terms of scope:
Class Mode: process the static relationship between classes and subclasses.
Object Mode: process the dynamic relationship between objects.
Classes in single-piece mode ensure that the class has only one instance in the system to ensure the correctness and efficiency of the logic.
Common method: Use a private constructor and use the read-only attribute or get method to generate a unique static instance. (Perform a double check before the Lock Object to apply to the multi-thread mode)
Method for generating new objects:
1. constructor;
2. serialization
In the. NET environment, the implementation of a more streamlined single-piece mode (compatible with multi-threaded environments ):
The disadvantage of this method is that it does not support parametric object construction. However, you can add an initiation method to complete object initialization.
Horizontal extension:
Single-piece mode can be extended to n-piece Mode
Vertical extension:
In single-piece mode, the object construction can still be carried out in new, and the logic for controlling the object generation can be placed in the constructor. Pay attention to the processing in the multi-threaded environment.
<End>