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)