java 完成搭建者方式

2021-04-05 04:09 jianzhan

Contents

1 java 完成搭建者方式1.0.0.0.1 结构者方式的优势1.0.1 要结构的很繁杂的目标1.0.1.1 建立搭建者1.0.1.2 建立检测 java 完成搭建者方式 结构者方式的优势

①应用修建者方式可使顾客端无须了解商品內部构成的关键点。

②实际的修建者类中间是互相单独的,这有益于系统软件的拓展。

③实际的修建者互相单独,因而能够对修建的全过程逐渐优化,而不容易对别的控制模块造成一切危害。

要结构的很繁杂的目标


5  package construct; public class Computer { // 显示信息器 private String display; // 行为主体 private String mainUnit; // 电脑鼠标 private String mouse; // 电脑键盘 private String keyboard; @Override public String toString() { return "Computer{" + "display='" + display + '\'' + ", mainUnit='" + mainUnit + '\'' + ", mouse='" + mouse + '\'' + ", keyboard='" + keyboard + '\'' + '}'; } public String getDisplay() { return display; } public void setDisplay(String display) { this.display = display; } public String getMainUnit() { return mainUnit; } public void setMainUnit(String mainUnit) { this.mainUnit = mainUnit; } public String getMouse() { return mouse; } public void setMouse(String mouse) { this.mouse = mouse; } public String getKeyboard() { return keyboard; } public void setKeyboard(String keyboard) { this.keyboard = keyboard; }} 
package construct;import construct.Computer; import java.util.Comparator; public class ComouterBuilder { puter = new Computer(); public void setDisplay(String display){&puter.setDisplay(display); } public void setMainUnit(String mainUnit){&puter.setMainUnit(mainUnit); } public void setMouse(String mouse){&puter.setMouse(mouse); } public void setKeyboard(String keyboard){&puter.setKeyboard(keyboard); } public Computer Builder(){&puter; }} 
package construct;import construct.ComouterBuilder;public class ConstructTest { public static void main(String[] args) {&puterBuilder = new ComouterBuilder();&puterBuilder.setDisplay("显示信息器");&puterBuilder.setMainUnit("服务器");&puterBuilder.setMouse("电脑鼠标");&puterBuilder.setKeyboard("电脑键盘"); Computer builder = computerBuilder.Builder(); System.out.println(builder); }}