(According to the msdn webcast courses)
The origin of the generator mode:
The main structure of a class (the construction method that combines members) is basically stable, but several internal components may change frequently.
Gof: separates the construction of a complex object from its representation, so that different representations can be created for the same build process.
The parta and B members that constitute an index of the main class change frequently, whileAlgorithmMethod unchanged, customerProgramUse the Construct Method of ctor to input different generators to create different types of objects.
The following example uses the generator mode to easily generate houses of various styles. You only need to implement the generator of this style house and pass it as a parameter to the createhouse method.
The specific classes are frequently changed:
The data generator generates corresponding objects, which do not need to be changed frequently:
Customer program call method:
When adding a new house style, the above method also needs to modify the input parameter type in the customer program. This is not the best method, but we can still use it. net reflection mechanism is dynamically loaded, so that the client program does not need to depend on the object of the class library layer.
Conclusion