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 ()