Design Mode Study Notes 4-builder Mode

Source: Internet
Author: User
Motivation : A complex object consists of multiple child objects. Algorithm Relatively unchanged, the composition of sub-objects changes dramatically. How to cope with the drastic changes of sub-objects, isolate relatively stable creation algorithms and variable sub-objects, so that customers can Program Does not change as the sub-object changes.

Scenario: ThinkPad series products, like General laptops, have relatively fixed components: motherboard, CPU, hard disk, display, keyboard ....... Assuming that all ThinkPad assembly processes are identical, different performance parameters are combined to form different types of ThinkPad, such as T43 and t60. How can we quickly assemble ThinkPad of a suitable model into a ThinkPad without changing the assembly process (taking the CPU and motherboard as an example?

Structure

CodeImplementation

/**/ /*
* Sub-object CPU
*/
Namespace Designpattern. Builder
{
Public   Abstract   Class CPU
{
}

Public   Class T43cpu: CPU
{
}

Public   Class T60cpu: CPU
{
}
}

/**/ /*
* Sub-object Motherboard
*/
Namespace Designpattern. Builder
{
Public   Abstract   Class Mainboard
{
}

Public   Class T43mainboard: mainboard
{
}

Public   Class T60mainboard: mainboard
{
}
}

/**/ /*
* Complex object ThinkPad
*/
Namespace Designpattern. Builder
{
Public   Abstract   Class ThinkPad
{
}

Public   Class T43thinkpad: ThinkPad
{
}

Public   Class T60thinkpad: ThinkPad
{
}
}

 

/**/ /*
* ThinkPad Generator
*/
Namespace Designpattern. Builder
{
Public   Abstract   Class Thinkpadbuilder
{
Public AbstractCPU buildcpu ();
Public AbstractMainboard buildmainboard ();
Public AbstractThinkPad getthinkpad ();
}

Public   Class T43builder: thinkpadbuilder
{< br> Public override CPU buildcpu ()

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.