● 阅读下列说明和Java代码,将应填入(n)处的字句写在答题纸的对应栏内。
【说明】
生成器( Builder)模式的意图是将一个复杂对象的构建与它的表示分离,使得同样的构建过程可以创建不同的表示。图6-1所示为其类图。
【Java代码】
import java.util.*;
class Product {
private String part A;
private String part B;
public Product__(6)__{}
public void setPartA(String s){ partA=s;}
public void setPartB(String s){ partB=s;}
}
interface Builder{
public (1);
public void buildPartB__(7)__;
public (2);
}
class ConcreteBuilder1: implements Builder{
private Product product;
public ConcreteBuilder1__(8)__{product=new Product__(9)__; }
public void buildPartA__(10)__{ (3)("Component A");}
public void buildPartB__(11)__{ (4)("Component B");}
public Product getResult__(12)__{ return product;}
}
class ConcreteBuilder2 implements Builder{
∥代码省略
}
class Director {
private Builder builder;
public Director(Builder builder){this.builder=builder;}
public void construct__(13)__{
(5)
∥代码省略
}
}
class Test{
public static void main(String[]args){
Director director1=new Director(new ConcreteBuilder1__(14)__);
director1.construct__(15)__;
}
}