Design Pattern-builder Pattern)

Source: Internet
Author: User

To put it simply, I am a real estate developer who wants to build a villa, but I don't know how to build it (simple wall building, low level ), I also don't know how to design it (Building a few rooms, a few good-looking doors and a high level). So I need to find a civil engineer who will build walls and a designer who knows how to design it, I also want to ensure that the Migrant Workers listen to the leaders of designers, and the designers themselves do not work, just give commands, here build a wall, here build a door, so that the migrant workers start construction, finally, I can ask migrant workers for a house. In this process, there is nothing for a designer, except for the design and command in his mind, so the house is also required for migrant workers.

/// <Summary>
/// The work required to build a house
/// </Summary>
Public interface ibuildhousework
{
Void buildbalcony ();
Void buildkitchen ();
Void buildbedroom ();
Void buildparlor ();
Domainmodel. Entities. House deliverhouse ();
}

/// <Summary>
/// Chinese construction workers only build Chinese houses
/// </Summary>
Public class chineseworker: ibuildhousework
{
Entities. House myhouse = new entities. House ();
Public void buildbalcony ()
{
Myhouse. balcony = "I have built a Chinese balcony ";
Console. writeline ("I have built a Chinese balcony ");
}

Public void buildkitchen ()
{
Myhouse. balcony = "I have built a Chinese Kitchen ";
Console. writeline ("I created a Chinese Kitchen ");
}

Public void buildbedroom ()
{
Myhouse. balcony = "I have built a Chinese bedroom ";
Console. writeline ("I have built a Chinese bedroom ");
}

Public void buildparlor ()
{
Myhouse. balcony = "I have built a Chinese living room ";
Console. writeline ("I created a Chinese living room ");
}
Public entities. House deliverhouse ()
{
Console. writeline ("made a Chinese-style house! ");
Return myhouse;

}
}

/// <Summary>
/// Western workers will build western houses
/// </Summary>
Public class worker: ibuildhousework
{
Entities. House myhouse = new entities. House ();
Public void buildbalcony ()
{
Myhouse. balcony = "I have built a western balcony ";
Console. writeline ("I have created a Western-style balcony ");
}

Public void buildkitchen ()
{
Myhouse. balcony = "I created a western Kitchen ";
Console. writeline ("I created a western Kitchen ");
}

Public void buildbedroom ()
{
Myhouse. balcony = "I have created a western bedroom ";
Console. writeline ("I have created a Western-style bedroom ");
}

Public void buildparlor ()
{
Myhouse. balcony = "I created a Western-style living room ";
Console. writeline ("I created a Western-style living room ");
}
Public entities. House deliverhouse ()
{
Console. writeline ("made a Western-style house! ");
Return myhouse;

}
}

/// <Summary>
/// Architect
/// </Summary>
Public class effecect
{
Ibuildhousework;
Public effecect (ibuildhousework)
{
This. Work = work;
}
Public void directwork ()
{
Work. buildbalcony ();
Work. buildbedroom ();
Work. buildkitchen ();
}
}

Client call

Static void main (string [] ARGs)
{
Ibuildhousework buildhouse = new chineseworker ();
Effecect chinesearchitect = new effecect (buildhouse );
Chinesearchitect. directwork ();
Buildhouse. deliverhouse ();

Buildhouse = new worker ();
Effecect westgateect = new effecect (buildhouse );
Westgateect. directwork ();
Buildhouse. deliverhouse ();
Console. Read ();
}

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.