C # Design Pattern--simply say (builder mode)

Source: Internet
Author: User

It is not so much a builder model as a popular factory production model. Of course, just for your own understanding and application patterns.

1, we need to generate the required components, a, b ...

2, the production line through the product QA, through the QA product is a finished product, one can display the product.

3, the product engineer, he gives you the manufacturing process documentation, tells you how to complete the assembly of this product

4, out of the product.

usingSystem;usingSystem.Collections.Generic;usingSystem.Linq;usingSystem.Text;namespaceBuilder Mode {//Workshop of the generated product     Public classProduct {Privateilist<string> parts =Newlist<string>(); //Add components sequentially         Public voidADD (stringPart ) {Parts.        ADD (part); }        //Installing Components         Public voidShow () {Console.WriteLine ("the product begins to assemble ..."); foreach(varIteminchparts) {Console.WriteLine ("Components"+ Item +"already installed."); } Console.WriteLine ("product completion. "); }    }    //Product Engineer     Public classBuilder {PrivateProduct Product =NewProduct (); //a module assembly         Public voidBuildparta () {product. ADD ("Mobile motherboard + Accessories"); }        //B Module Assembly         Public voidBUILDPARTB () {product. ADD ("Mobile phone Case"); }        //the products obtained         PublicProduct geproduct () {returnproduct; }        //assembled into a product         Public voidConstruct () {Buildparta ();            BUILDPARTB (); Product. ADD ("packaged into boxes"); }    }    classProgram {Private StaticBuilder Builder; Static voidMain (string[] args) {Builder=NewBuilder (); Builder.            Construct (); Product Product=Builder.            Geproduct (); Product.            Show ();        Console.read (); }    }}

See this picture, is not found a few things. That's right, the standard process is missing.

Improved under

usingSystem;usingSystem.Collections.Generic;usingSystem.Linq;usingSystem.Text;namespaceBuilder Mode {//Workshop of the generated product     Public classProduct {Privateilist<string> parts =Newlist<string>(); //Add components sequentially         Public voidADD (stringPart ) {Parts.        ADD (part); }        //Installing Components         Public voidShow () {Console.WriteLine ("the product begins to assemble ..."); foreach(varIteminchparts) {Console.WriteLine ("Components"+ Item +"already installed."); } Console.WriteLine ("product completion. "); }    }    //Product Engineer     Public classBuilder:phonebuilder {PrivateProduct Product =NewProduct (); //a module assembly         Public voidBuildparta () {product. ADD ("Mobile motherboard + Accessories"); }        //B Module Assembly         Public voidBUILDPARTB () {product. ADD ("Mobile phone Case"); }        //the products obtained         PublicProduct geproduct () {returnproduct; }        //assembled into a product         Public voidConstruct () {Buildparta ();            BUILDPARTB (); Product. ADD ("packaged into boxes"); }    }    //Create a mobile phone to the process, not cut corners     Public Abstract classPhonebuilder { Public Abstract voidBuildparta ();  Public Abstract voidBUILDPARTB ();  Public Abstract voidgeproduct ();  Public Abstract voidConstruct (); }    classProgram {Private StaticBuilder Builder; Static voidMain (string[] args) {Builder=NewBuilder (); Builder.            Construct (); Product Product=Builder.            Geproduct (); Product.            Show ();        Console.read (); }    }}

C # Design Pattern--simply say (builder mode)

Related Article

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.