阅读以下说明和Jrdva代码,将应填入(n)处的字句写在对应栏内。[说明]在销售系统中常常需要打印销售票据,有时需要在一般的票据基础上打印脚注。这样就需要动态地添加一些额外的职责。如下展示了Decorator(修饰)模式。SalesOrder对象使用一个SalesTicket对象打印销售票据。图6-1显示了各个类间的关系。以下是Java语言实现,能够正确编译通过。[图6-1][Java代码]//Component.java文件public (1) class Component {abstract publ ic void prtTicket();}//salesTicket.java文件public class SalesTicket extends Component{public void prtTicket(){//Sales ticket printing code hereSystem.out.printin("SalesTicket");}}//Decorator.java文件publ ic abstract class Decorator extends Component{public void prtTicket(){if(myComp!=null)myComp.prtTicket();}private (2) myComp;public Decorator(Component myC){myComp=myC;}}//Footer.java文件public class Footer extends Decorator {public Footer(Component myC){(3);}public void prtTicket(){(4);prtFooter();}publ ic void prtFooter(){//place printing footer code hereSystem.out.println("Footer");}}//salesorder.java文件public class SalesOrder{void prtTicket(){Component myST;myST=new Footer( (5) );//Print Ticket with footers as neededmyST.prtTicket();}}(1)

阅读以下说明和Jrdva代码,将应填入(n)处的字句写在对应栏内。

[说明]

在销售系统中常常需要打印销售票据,有时需要在一般的票据基础上打印脚注。这样就需要动态地添加一些额外的职责。如下展示了Decorator(修饰)模式。SalesOrder对象使用一个SalesTicket对象打印销售票据。图6-1显示了各个类间的关系。以下是Java语言实现,能够正确编译通过。

[图6-1]

[Java代码]

//Component.java文件

public (1) class Component {

abstract publ ic void prtTicket();

}

//salesTicket.java文件

public class SalesTicket extends Component{

public void prtTicket(){

//Sales ticket printing code here

System.out.printin("SalesTicket");

}

}

//Decorator.java文件

publ ic abstract class Decorator extends Component{

public void prtTicket(){

if(myComp!=null)myComp.prtTicket();

}

private (2) myComp;

public Decorator(Component myC){

myComp=myC;

}

}

//Footer.java文件

public class Footer extends Decorator {

public Footer(Component myC){

(3);

}

public void prtTicket(){

(4);

prtFooter();

}

publ ic void prtFooter(){

//place printing footer code here

System.out.println("Footer");

}

}

//salesorder.java文件

public class SalesOrder{

void prtTicket(){

Component myST;

myST=new Footer( (5) );

//Print Ticket with footers as needed

myST.prtTicket();

}

}

(1)


相关考题:

试题八(共15分)阅读以下说明和Java程序代码,将应填入(n) 处的字句写在答题纸的对应栏内。[说明]在下面的 Java 程序代码中,类SalesTicket 能够完成打印票据正文的功能,类HeadDecorator 与FootDecorator 分别完成打印票据的台头和脚注的功能。已知该程序运行后的输出结果如下所示,请填补该程序代码中的空缺。这是票据的台头!这是票据正文!这是票据的脚注!------------------------这是票据的台头!这是票据的脚注![Java程序代码]public class SalesTicket {public void printTicket() {System.out.println("这是票据正文!");}}public class Decorator extends SalesTicket{SalesTicket ticket;}}public class FootDecorator extends Decorator{public FootDecorator(SalesTicket t) {(2) ;}public void printTicket() {super.printTicket();System.out.println("这是票据的脚注!");}}public class Main {public static void main(String[] args) {T = new HeadDecorator( (3) );T. (4) ;System.out.println("------------------------");T = new FootDecorator( (5) );T.printTicket();}}public Decorator(SalesTicket t){ticket = t;}public void printTicket(){if(ticket != null)ticket.printTicket();}}public class HeadDecorator extends Decorator{public HeadDecorator(SalesTicket t) {(1) ;}public void printTicket() {System.out.println("这是票据的台头!");super.printTicket();

试题五(共15分)阅读下列说明和C++-代码,将应填入 (n) 处的字句写在答题纸的对应栏内。【说明】某发票(lnvoice)由抬头(Head)部分、正文部分和脚注(Foot)部分构成。现采用装饰( Decorator)模式实现打印发票的功能,得到如图5-1所示的类图。【C++代码】include iostreamusing 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 分)阅读以下说明和 C 程序,将应填入 (n) 处的字句写在答题纸的对应栏内。

阅读下列函数说明和C++代码,将应填入(n)处的字句写在对应栏内。[说明]在销售系统中常常需要打印销售票据,有时需要在一般的票据基础上打印脚注。这样就需要动态地添加一些额外的职责。如下展示了Decorator(修饰)模式。SalesOrder对象使用一个SalesTicket对象打印销售票据,先打印销售票据内容,然后再打印脚注。图5-1显示了各个类间的关系。以下是C++语言实现,能够正确编译通过。[图5-1][C++代码]class Component{public:(1) void prtTicket()=0;};class SalesTicket:public Component{public:void prtTicket(){cout<<"Sales Ticket!"<<endl;}};class Decorator:public Component{public:virtual void prtTicket();Decorator(Component *myC);private:(2) myComp;};Decorator::Decorator(Component *myC){myComp=myC;}void Decorator::prtTicket(){myComp->prtTicket();}class Footer:public Decorator{public:Footer(Component *myC);void prtTicket();void prtFooter();};Footer::Footer(Component *myC): (3) {}void Footer::prtFooter(){cout<<"Footer"<<endl;}void Footer::prtTicket(){(4) ;prtFooter();}class SalesOrder{public:void prtTicket();};void SalesOrder::prtTicket(){Component *myST;myST=new Footer( (5) );myST->prtTicket();}(1)

阅读以下说明和C++程序代码,将应填入(n)处的字句写在答题纸的对应栏内。【说明】在下面的C++代码中,类SalesTicket能够完成打印票据正文的功能,类HeadDec- orator与FootDecorator分别能够完成打印票据的台头和脚注的功能。已知该程序运行后的输出结果如下所示,请填补该程序代码中的空缺。这是票据的台头!这是票据正文!这是票据的脚注!---------------这是票据的台头!这是票据的脚注!【C++程序代码】#includeusing namespace std;class SalesTicket {public:(1) printTicket() { cout " 是票据正文!" endl;}class Decorator : public SalesTicket{SalesTicket *ticket;public:Decorator(SalesTicket *t){ ticket = t; }void printTicket(){if(ticket != NULL)ticket->printTicket();}};class HeadDecorator : public Decorator{public:HeadDecorator(SalesTicket *t): (2) { }void printTicket() {sour "这是票据的台头!" endl;Decorator::printTicket();}};class FootDecorator :public Decorator{public:FootDecorator(SalesTicket *t): (3)void printTicket() {Decorator::printTicket();cout "这是票据的脚注!" endl;}};void main(void) {SalesTicket t;FootDecorator f(t);HeadDecorator h( (4) );h.printTicket();cout "-------------------------" endl;FootDecorator a(NULL);HeadDecorator b( (5) );b.printTicket();}

阅读以下说明和Java程序代码,将应填入(n)处的字句写在答题纸的对应栏内。【说明】在下面的Java程序代码中,类SalesTicket能够完成打印票据正文的功能,类 HeadDecorator与FootDecorator分别能够完成打印票据的台头和脚注的功能。已知该程序运行后的输出结果如下所示,请填补该程序代码中的空缺。这是票据的台头!这是票据正文!-------------------这是票据的脚注!这是票据的台头!这是票据的脚注!【tava程序代码】public class SalesTicket {public void printTicket() {System. out. println ( "这是票据正文 ! ");}}public class Decorator extends SalesTicket{SalesTicket ticket;public Decorator(SalesTicket t) {ticket = t;}public void printTicket(){if(ticket != null)ticket.printTicket();}public class HeadDecorator extends Decorator{public HeadDecorator(SalesTicket t) {(1)}public void printTicket() {System. out.println("这是票据的台头! ");super.printTicket();}}public class FootDecorator extends Decorator{public FootDecorator(SalesTicket t) {(2);}public void printTicket() {super, printTicket ();System. out.println ("这是票据的脚注!");}}public class Main {public static void main(String[] args) {T = new HeadDecorator( (3));T=(4);System.out.println("------------------------------------");T = new FootDecorator((5));T.printTicket ();}}

阅读下列说明和C++-代码,将应填入(n)处的字句写在答题纸的对应栏内。 【说明】 某发票(lnvoice)由抬头(Head)部分、正文部分和脚注(Foot)部分构成。现采用装饰(Decorator)模式实现打印发票的功能,得到如图5-1所示的类图。【C++代码】 #include using namespace std; class invoice{ public: (1){ cout

阅读下列说明和C++-代码,将应填入 (n) 处的字句写在答题纸的对应栏内。【说明】 某发票(lnvoice)由抬头(Head)部分、正文部分和脚注(Foot)部分构成。现采用装饰( Decorator)模式实现打印发票的功能,得到如图5-1所示的类图。【C++代码】#includeusingnamespace std;class Invoice{public: (1) { coutinvoice!" }};classDecorator : public Invoice { Invoice *ticket;public: Decorator(lnvoice *t) { ticket = t; } void printInvoice( ){ if(ticket != NULL) (2); } };classHeadDecorator : public Decorator{public: HeadDecorator(lnvoice*t): Decorator(t) { } void printInvoice( ) { coutheader of the invoice! " (3) ; } }; class FootDecorator : public Decorator{ public: FootDecorator(Invoice *t): Decorator(t) { } void printlnvoice( ){ (4) ; coutfootnote of the invoice!" }};int main(void){ Invoice t; FootDecorator f( HeadDecorator h( h.printInvoice( ); cout 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!

阅读下列说明和?C++代码,将应填入(n)处的字句写在答题纸的对应栏内。【说明】阅读下列说明和?Java代码,将应填入?(n)?处的字句写在答题纸的对应栏内。【说明】某快餐厅主要制作并出售儿童套餐,一般包括主餐(各类比萨)、饮料和玩具,其餐品种类可能不同,但其制作过程相同。前台服务员?(Waiter)?调度厨师制作套餐。现采用生成器?(Builder)?模式实现制作过程,得到如图?6-1?所示的类图。