摘要:2018上半年軟件設(shè)計師考試已結(jié)束,小編為大家整理了2018上半年軟件設(shè)計師下午真題,以下為第三部分。
● 閱讀下列說明和Java代碼,將應(yīng)填入(n)處的字句寫在答題紙的對應(yīng)欄內(nèi)。
【說明】
生成器( Builder)模式的意圖是將一個復(fù)雜對象的構(gòu)建與它的表示分離,使得同樣的構(gòu)建過程可以創(chuàng)建不同的表示。圖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)__;
}
}
軟考備考資料免費領(lǐng)取
去領(lǐng)取