下载此文档

中南大学软件体系结构设计模式实验二全解.pdf


文档分类:高等教育 | 页数:约19页 举报非法文档有奖
1/19
下载提示
  • 1.该资料是网友上传的,本站提供全文预览,预览什么样,下载就什么样。
  • 2.下载该文档所得收入归上传者、原创者。
  • 3.下载的文档,不会出现我们的网址水印。
1/19 下载此文档
文档列表 文档介绍
该【中南大学软件体系结构设计模式实验二全解 】是由【青山代下】上传分享,文档一共【19】页,该文档可以免费在线阅读,需要了解更多关于【中南大学软件体系结构设计模式实验二全解 】的内容,可以使用淘豆网的站内搜索功能,选择自己适合的文档,以下文字是截取该文章内的部分文字,如需要获得完整电子版,请下载此文档到您的设备,方便您编辑和打印。:..实验报告设计模式实验2专业班级学号姓名实验成绩:批阅教师:年月日1:..设计模式实验二4每组人数:1实验类型:3(12:综合性3:设计性4:研究性)实验要求:1(1:必修2:选修3:其它)实验类别:3(1:基础2:专业基础3:专业4:其它)一、实验目的熟练使用PowerDesigner和任意一种面向对象编程语言实现几种常见的行为型设计模式,包括职责链模式、命令模式、观察者模式和策略模式,理解每一种设计模式的模式动机,掌握模式结构,学****如何使用代码实现这些模式。二、(SupplyChainManagement,供应链管理)系统中包含一个采购审批子系统。该企业的采购审批是分级进行的,即根据采购金额的不同由不同层次的主管人员来审批,主任可以审批5万元以下(不包括5万元)的采购单,副董事长可以审批5万元至10万元(不包括10万元)的采购单,董事长可以审批10万元至50万元(不包括50万元)的采购单,50万元及以上的采购单就需要开董事会讨论决定。如下图所示:金额<5万元5万元≤金额<10万元10万元≤金额<50万元金额≥50万元采购单采购人员主任副董事长董事长董事会试使用职责链模式设计并模拟实现该系统。,现用命令模式来模拟开关的功能,可控制对象包括电灯和电风扇,绘制相应的类图并编程模拟实现。。系统提供一个主菜单(Menu),在主菜单中包含了一些菜单项(MenuItem),可以通过Menu类的addMenuItem()方法增加菜单项。菜单项的主要方法是click(),每一个菜单项包含一个抽象命令类,具体命令mand(打开命令),mand(新建命令),mand(编辑命令)等,命令类具有一个execute()方法,用于调用公告板系统界面类(BoardScreen)的open()、create()、edit()等方法。现使用命令模式设计该系统,使得MenuItem类与BoardScreen类的耦合度降低,绘制类图并编程实现。2:..%时,系统将自动发送通知(包括新价格)给购买该股票的所有股民。试使用观察者模式设计并实现该系统,要求绘制相应的类图并编程模拟实现。,如果机房达到某一指定温度,温度传感器(Thermosensor)将自动传递信号给各种响应设备,例如警示灯(CautionLight)将闪烁(flicker())、报警器(Annunciator)将发出警报(alarm())、安全逃生门(SecurityDoor)将自动开启(open())、隔热门(InsulatedDoor)将自动关闭(close())等,每一种响应设备的行为由专门的程序来控制。为了将来能够方便地引入新类型的响应设备,采用观察者模式和适配器模式设计并模拟实现该系统。,在该系统中需要为不同类型的用户提供不同的电影票(MovieTicket)打折(Discount)方式,具体打折方案如下:(1)学生凭学生证可享受票价8折优惠;(2)年龄在10周岁及以下的儿童可享受每张票减免10元的优惠(原始票价需大于等于20元);(3)影院VIP用户除享受票价半价优惠外还可进行积分,积分累计到一定额度可换取电影院赠送的奖品。该系统在将来可能还要根据需要引入新的打折方式。试使用策略模式设计并编程模拟实现该影院售票系统。,某公司欲开发一款手机数码照片处理软件,在该软件中为照片(Photograph)提供了多种滤镜(Filter)效果,例如黑白滤镜(BlackWhiteFilter)、单色滤镜(MonochromaticFilter)、怀旧滤镜(NostalgicFilter)等,不同的滤镜通过不同的算法对照片进行美化,如下图所示。该软件可以灵活地增加一些新的滤镜效果。选择一种合适的设计模式来设计该照片处理软件,结合场景绘制相应的类图并编程模拟实现。3:..,正确无误地绘制职责链模式、命令模式、观察者模式和策略模式的模式结构图;、命令模式、观察者模式和策略模式实例,代码运行正确无误。四、,使用PowerDesigner绘制职责链模式实例结构图并用面向对象编程语言实现该模式实例;,使用PowerDesigner绘制命令模式实例结构图并用面向对象编程语言实现该模式实例;,使用PowerDesigner绘制命令模式实例结构图并用面向对象编程语言实现该模式实例;,使用PowerDesigner绘制观察者模式实例结构图并用面向对象编程语言实现该模式实例;,使用PowerDesigner绘制观察者模式实例结构图并用面向对象编程语言实现该模式实例;,使用PowerDesigner绘制策略模式实例结构图并用面向对象编程语言实现该模式实例;,使用PowerDesigner绘制策略模式实例结构图并用面向对象编程语言实现该模式实例。五、:PurchaseRequest-amount:double-essor:Approver-number:int+essor(essor):void-prupose:String+processRequest(:voidPurchaseRequestqRequest)...CongressDirectorVicePresidentPresident4:..classPurchaseRequest{publicdoubleamount;publicintnumber;publicStringpurpose;publicdoublegetAmount(){returnamount;}publicvoidsetAmount(doubleamount){=amount;}publicintgetNumber(){returnnumber;}publicvoidsetNumber(intnumber){=number;}publicStringgetPurpose(){returnpurpose;}publicvoidsetPurpose(Stringpurpose){=purpose;}}lassApprover{esor;publicApprover(){esor=null;}publicvoidprocessRequest(PurchaseRequestaRequest){if(esor!=null){(aRequest);}}esor(esor){=esor;}}lassCongressextendsApprover{5:..voidprocessRequest(PurchaseRequestrequest){if(()>=500000){System.}}}lassDirectorextendsApprover{publicvoidprocessRequest(PurchaseRequestrequest){if(()<50000){}else{if(!=null){(request);}}}}lassPresidentextendsApprover{publicvoidprocessRequest(PurchaseRequestrequest){if(()<500000){}else{if(!=null){(request);}}}}lassVicePresidentextendsApprover{publicvoidprocessRequest(PurchaseRequestrequest){if(()<100000){}else{if(!=null){(request);}}}}6:..-command:mand+open():void+close():void...{abstract}+excute():void...mandFun-light:Light-fun:Fun+open():void+excute():void+excute():void+open():void+close():void+close():void......实现代码:mand{publicabstractvoidopen();publicabstractvoidclose();}lassSwitch{mand;mand(mand){mand;}publicvoidopen(){();}publicvoidclose(){();}}lassFun{publicvoidopen(){}publicvoidclose(){}}7:..classLight{publicvoidopen(){System.}publicvoidclose(){}}mand{privateFunfun=newFun();***@Overridepublicvoidopen(){//TODOAuto-();}***@Overridepublicvoidclose(){//TODOAuto-();}}mand{privateLightlight=newLight();***@Overridepublicvoidopen(){//TODOAuto-();}***@Overridepublicvoidclose(){//TODOAuto-();}}8:..-itemList:ArrayListBoardScreen+addMenuItem(MenuItemitem):void-menu:Menu+BoardScreen()+display():void+open():void+create():voidMenuItem+edit():void-name:String...-mand+<<Constructor>>MenuItem(Stringname)+getName():String+setName():void+mand():Command+mand):void+click():void...+excute():void...mandmand-screen:BoardScreen+mand(BoardScreenscreen)-screen:BoardScreen+excute():void+mand(mandscreen)...+excute():void...mand-screen:BoardScreen+mand(BoardScreenscreen)+excute():void...实现代码:mand{publicvoidexcute();}lassMenuItem{privateStringname;mand;publicMenuItem(Stringname){=name;}publicStringgetName(){returnname;}publicvoidsetName(Stringname){=name;}mand(){mand;9:..}mand){mand;}publicvoidclick(){();}};lassMenu{publicArrayListitemList=newArrayList();publicvoidaddMenuItem(MenuItemitem){(item);}}mand{privateBoardScreenscreen;mand(BoardScreenscreen){super();=screen;}***@Overridepublicvoidexcute(){//TODOAuto-();}}mand{privateBoardScreenscreen;mand(BoardScreenscreen){super();=screen;}***@Overridepublicvoidexcute(){10:..//Auto-();}}mand{privateBoardScreenscreen;mand(BoardScreenscreen){super();=screen;}***@Overridepublicvoidexcute(){//TODOAuto-();}}lassBoardScreen{privateMenumenu;privateMenuItemopenItem,createItem,editItem;publicBoardScreen(){menu=newMenu();openItem=newcreateItem=new新建editItem=(openItem);(createItem);(editItem);}publicvoiddisplay(){:for(Objectobj:){(((MenuItem)obj).getName());}}publicvoidopen(){!}11:..voidcreate(){System.}publicvoidedit(){!}publicMenugetMenu(){returnmenu;}}:Stock-investors:ArrayList-stockName:String-price:double+Stock()+response(Stockstock):void+attach(Investorinestor):void...+detach(Investorinvestor):void+nitifyInvestor():void...ConcreteInvestor-name:String+<<Implement>>response(Stockstock):void+ConcreteInvestor(Stringname)...实现代码:publicinterfaceInvestor{publicvoidresponse(Stockstck);}lassConcreteInvestorimplementsInvestor{privateStringname;oncreteInvestor(Stringname){super();=name;}***@Overridepublicvoidresponse(Stockstock){//TODOAuto-:..}};lassStock{privateArrayList<Investor>investors;privateStringstockName;privatedoubleprice;publicStock(StringstockName,doubleprice){super();=stockName;=price;investors=newArrayList<Investor>();}publicvoidattach(Investorinvestor){(investor);}publicvoiddetach(Investorinvestor){(investor);}publicvoidnotifyInvestor(){for(Objectobj:investors){((Investor)obj).response(this);}}publicStringgetStockName(){returnstockName;}publicvoidsetStockName(StringstockName){=stockName;}publicdoublegetPrice(){returnprice;}publicvoidsetPrice(doubleprice){doublerange=Math.(price-)/;=price;if(range>=){();}}13:..}classClient{publicstaticvoidmain(String[]args){Investorinvestor1,investor2;investor1=newinvestor2=new呵呵Stockhaier=(investor1);(investor2);();}}:Thermosensor-alarmListener:ArrayList+attach(AlarmListeneralarmListener):void+detach(AlarmListeneralarmListener):void+response():void+notify():void......CautionLightInsulatedDoor+flicker():void+close():voidAnnunciatorSecurityDoor+alarm():void+open():void实现代码:publicinterfaceAlarmListener{publicvoidresponse();}lassAnnunciatorimplementsAlarmListener{privateAnnunciatorannunciator;***@Overridepublicvoidresponse(){//TODOAuto-generatedmethodstub14:..();}voidalarm(){System.}}lassCautionLightimplementsAlarmListener{privateCautionLightlight;***@Overridepublicvoidresponse(){//TODOAuto-();}publicvoidflicker(){}}lassInsulatedDoorimplementsAlarmListener{privateInsulatedDoorinsulatedDoor;***@Overridepublicvoidresponse(){//TODOAuto-();}publicvoidclose(){}}lassSecurityDoorimplementsAlarmListener{privateSecurityDoorsecurityDoor;***@Overridepublicvoidresponse(){//TODOAuto-();15:..}voidopen(){System.}};lassThermosensor{privateArrayList<AlarmListener>alarm;publicvoidattach(AlarmListenerlistener){(listener);}publicvoiddetach(AlarmListenerlistener){(listener);}publicvoidnotifyAlarm(){for(Objectobj:alarm){((AlarmListener)obj).response();}}}:MovieTicket-price:double-discount:Discount+setPrice(doubleprice):void+setDiscount(Discountdiscount):void+calculate(doubleprice):double...+getPrice():double...StudentDiscountVIPDiscountChildrenDiscount实现代码:publicinterfaceDiscount{publicdoublecalculate(doubleprice);}16:..classCIPDiscountimplementsDiscount{***@Overridepublicdoublecalculate(doubleprice){//TODOAuto-*;}}lassMovieTicket{privatedoubleprice;privateDiscountdiscount;publicdoublegetPrice(){(price);}publicDiscountgetDiscount(){returndiscount;}publicvoidsetDiscount(Discountdiscount){=discount;}}lassChildrenDiscountimplementsDiscount{***@Overridepublicdoublecalculate(doubleprice){//TODOAuto-generatedmethodstubreturnprice-10;}}lassStudentDiscountimplementsDiscount{***@Overridepublicdoublecalculate(doubleprice){//TODOAuto-generatedmethodstubreturnprice*;}}17:..-filter:Filter+decorate():void+method():void...BlackWhiteFilterMonochromaticFilterNostalgicFilter+<<Implement>>method():void+<<Implement>>method():void+<<Implement>>method():void实现代码:interfaceFilter{publicvoidmethod();}lassMonochromaticFilterimplementsFilter{***@Overridepublicvoidmethod(){//TODOAuto-}}lassNostalgicFilterimplementsFilter{***@Overridepublicvoidmethod(){//TODOAuto-}}lassBlackWhiteFilterimplementsFilter{***@Overridepublicvoidmethod(){//TODOAuto-}18:..}classPhotograph{privateFilterfilter;publicvoiddecorate(){();}}通过本次实验,学会了使用职责链模式、命令模式、观察者模式、策略模式等行为型模式进行设计程序,在实验过程中遇到了类与类之间关系不确定的问题,通过复****该模式的原理和实现方法得到解决。本次实验中有些行为型模式应用仍不熟练,需要勤加练****19

中南大学软件体系结构设计模式实验二全解 来自淘豆网www.taodocs.com转载请标明出处.

相关文档 更多>>
非法内容举报中心
文档信息
  • 页数19
  • 收藏数0 收藏
  • 顶次数0
  • 上传人青山代下
  • 文件大小1.60 MB
  • 时间2024-04-14