创建型模式-Creational Patterns-Builder
将一个复杂对象的构建与其表示相分离,使得同样的构建过程可以创建不同的表示。《设计模式》GoF
seperate the construction of a complex object from it representation so that the same construction process can create different representions.
Builder 模式的几个要点
• Builder 模式主要用于“分步骤构建一个复杂的对
象”。在这其中“分步骤”是一个稳定的算法,而复
杂对象的各个部分则经常变化。
• 变化点在哪里,封装哪里—— Builder模式主要在
于应对“复杂对象各个部分”的频繁需求变动。其
缺点在于难以应对“分步骤构建算法”的需求变动。
• Abstract Factory模式解决“系列对象”的需求变
化,Builder模式解决“对象部分”的需求变化。
Builder模式通常和Composite模式组合使用。
public class main()
{
//read builder class name from config file
configrationSetting
House house = GameManager.CreateHouse(new ModernHouseBuilder());
}