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