CSHARP design mode Reading Notes (6): builder mode (learning difficulty:★★★★☆Usage frequency:★★☆☆)

Source: Internet
Author: User

Mode roles and modes:

The builder model can separate the internal appearance of a product from the production process of the product, so that it can be a product object with different internal appearances generated during the construction process.

Using system;
Using system. collections;

Namespace csharpdesignpattern. builderpattern
{
Public class product
{
Arraylist parts = new arraylist ();
Public void add (string part)
{
Parts. Add (part );
}
}

Public interface ibuilder
{
Void buildparta ();
Void buildpartb ();
Product getresult ();
}

Public class concretebuilder1: ibuilder
{
Private product;

Public void buildparta ()
{
Product = new product ();
Product. Add ("parta ");
}

Public void buildpartb ()
{
Product. Add ("partb ");
}

Public Product getresult ()
{
Return product;
}
}

Public class concretebuilder2: ibuilder
{
Private product;

Public void buildparta ()
{
Product = new product ();
Product. Add ("partx ");
}

Public void buildpartb ()
{
Product. Add ("party ");
}

Public Product getresult ()
{
Return product;
}
}

Class director
{
Public void construct (ibuilder builder)
{
Builder. buildparta ();
Builder. buildpartb ();
}
}

Class Program
{
Static void main (string [] ARGs)
{
Director dire= new director ();

Ibuilder b1 = new concretebuilder1 ();
Ibuilder b2 = new concretebuilder2 ();

Director. Construct (B1 );
Product p1 = b1.getresult ();

Director. Construct (B2 );
Product P2 = b2.getresult ();

Console. Readline ();
}
}
}

 


 

 

CSHARP design mode Reading Notes (6): builder mode (learning difficulty:★★★★☆Usage frequency:★★☆☆)

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.