装饰器 (Decorator) 模式用于();外观 (Facade) 模式用于()。 ①将一个对象加以包装以给客户提供
装饰器 (Decorator) 模式用于();外观 (Facade) 模式用于()。 ①将一个对象加以包装以给客户提供其希望的另外一个接口 ②将一个对象加以包装以提供一些额外的行为 ③将一个对象加以包装以控制对这个对象的访问 ④将一系列对象加以包装以简化其接口
A.①B.②C.③D.④A.①B.②C.③D.④
装饰器 (Decorator) 模式用于();外观 (Facade) 模式用于()。 ①将一个对象加以包装以给客户提供其希望的另外一个接口 ②将一个对象加以包装以提供一些额外的行为 ③将一个对象加以包装以控制对这个对象的访问 ④将一系列对象加以包装以简化其接口
A.①B.②C.③D.④A.①B.②C.③D.④
A.Iterator(迭代器)
B.Decorator(装饰器)
C.Interpreter(解释器)
D.Adapter(适配器)
A.桥接(Bridge)
B.适配器(Adapter)
C.组成(Composite)
D.装饰器(Decorator)
下图所示为(46)设计模式,
A.组件(Component)
B.适配器(Adapter)
C.组合(Composite)
D.装饰器(Decorator)
A.桥接(Bridge) B.适配器(Adapter) C.组成(Composite) D.装饰器 (Decorator) A.桥接(Bridge) B.适配器(Adapter) C.组成(Composite) D.装饰器 (Decorator)
A.桥接(Bridge)
B.适配器(Adapter)
C.组成(Composite)
D.装饰器(Decorator)
为图形用户界面(GUI)组件定义不同平台的并行类层次绩构,适合采用()模式。
A.享元(Flyweight)
B.抽象工厂(Abstract Factory)
C.外观(Facade))
D.装饰器(Decorator)
● 设计模式中的(45)模式将对象组合成树形结构以表示“部分-整体”的层次结构,使得客户对单个对象和组合对象的使用具有一致性。下图为该模式的类图,其中,(46)定义有子部件的那些部件的行为;组合部件的对象由(47)通过component提供的接口操作。
(45)A.代理(Proxy)
B.桥接器(Bridge)
C.组合(Composite)
D.装饰器(Decorator)
(46) A. Client
B. Component
C. Leaf
D. Composite
(47) A. Client
B. Component
C. Leaf
D. Composite
(41)
A. Facade(外观)
B. Singleton(单件)
C. Participant(参与者)
D. Decorator(装饰)
(42)
A. Facade(外观)
B. Singleton(单件)
C. Participant(参与者)
D. Decorator(装饰)
试题五(共15分)
阅读下列说明和C++-代码,将应填入 (n) 处的字句写在答题纸的对应栏内。
【说明】
某发票(lnvoice)由抬头(Head)部分、正文部分和脚注(Foot)部分构成。现采用装饰(Decorator)模式实现打印发票的功能,得到如图5-1所示的类图。
【C++代码】
include <iostream>
using namespace std;
class invoice{
public:
(1) {
cout《 "This is the content of the invoice!"《 endl;
}
};
class Decorator : public invoice {
Invoice *ticket;
public:
Decorator(lnvoice *t) { ticket = t; }
void printinvoice(){
if(ticket != NULL)
(2);
}
};
class HeadDecorator : public Decorator{
public:
HeadDecorator(lnvoice*t): Decorator(t) { }
void printinvoice0 {
cout《 "This is the header of the invoice! "<< endl;
(3) ;
}
};
class FootDecorator : public Decorator{
public:
FootDecorator(invoice *t): Decorator(t) { }
void printlnvoice() {
(4) ;
cout《 "This is the footnote of the invoice!"《 endl;
}
};
int main(void) {
Invoice t;
FootDecorator f(&t);
HeadDecorator h(&f);
H.printlnvoice();
cout< < “_____”< < endl;
FootDecorator a(NULL);
HeadDecorator b((5) );
B.printinvoice();
return 0;
}
程序的输出结果为:
This is the header of the invoice!
This is the content of the invoice!
This is the footnote of the invoice!
----------------------------
This is the header of the invoice!
This is the footnote of the invoice!
试题六(共15分)
阅读下列说明和Java代码,将应填入 (n) 处的字句写在答题纸的对应栏内。
【说明】
某发票(lnvoice)由抬头(Head)部分、正文部分和脚注(Foot)部分构成。现采用装饰(Decorator)模式实现打印发票的功能,得到如图6-1所示的类图。
【java代码】
class invoice{
public void printInvoice(){:
System.out.println ("This is the content of the invoice!");
}
}
class Decorator : extends Invoice {
protected Invoice ticket;
public Decorator(lnvoice t){
ticket = t;
}
public void printinvoice(){
if(ticket != NULL)
(1);
}
}
class FootDecorator extends Decorator{
public FootDecorator(lnvoice t){
super(t);
}
public void printinvoice (){
Systent.out.println("This is the header of the invoice! ");
(2) ;
}
}
class FootDecorator extends Decorator {
public FootDecorator(invoice t):{
super(t);
}
public void printlnvoice(){
(3) ;
Systent.out.println("This is the header of the invoice! ");
}
}
Class test {
public static void main(string[] args){
Invoice t =new invioce();
Invoice ticket;
Ticket= (4) ;
Ticket. Printinvoice();
Systent.out.println(“--------------“)
Ticket= (5) ;
Ticket. Printinvoice();
}
}
程序的输出结果为:
This is the header of the invoice!
This is the content of the invoice!
This is the footnote of the invoice!
----------------------------
This is the header of the invoice!
This is the footnote of the invoice!