C # object-oriented design mode Lecture 4: builder pattern generator mode (Creation Mode)

Source: Internet
Author: User

(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

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: info-contact@alibabacloud.com 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.