收藏 分销(赏)

C#模式设计习题分析.doc

上传人:a199****6536 文档编号:3903334 上传时间:2024-07-23 格式:DOC 页数:9 大小:318.67KB
下载 相关 举报
C#模式设计习题分析.doc_第1页
第1页 / 共9页
C#模式设计习题分析.doc_第2页
第2页 / 共9页
C#模式设计习题分析.doc_第3页
第3页 / 共9页
C#模式设计习题分析.doc_第4页
第4页 / 共9页
C#模式设计习题分析.doc_第5页
第5页 / 共9页
点击查看更多>>
资源描述

1、。第三章 简单工厂模式5、使用简单工厂模式设计一个可以创建不同几何形状(Shape),如圆形(Circle)、矩形(Rectangle)和三角形(Triangle)等的绘图工具类,每个几何图形均具有回执Draw()和擦除Erase()两个方案,要求在绘制不支持的几何图形时,抛出一个UnsupportedShapeException异常,绘制类图并使用C#语言编程模拟实现Shape+Draw() : void+Erase() : voidShapeFactory+ShapeProduce(string type) : ShapeCircle+Draw() : void+Erase() : voi

2、dTriangle+Draw() : void+Erase() : voidRectangle+Draw() : void+Erase() : voidUnsupportedShapeException+UnsupportedShapeException() 实例类图:上图中,Shape接口充当抽象产品类,其子类Circle、Triangle、Rectangle和UnsupportedShapeException充当具体产品类,ShapeFactory充当工厂类。第五章 抽象工厂模式5、一个电器工厂可以生产多种类型的电器,如海尔工厂可以生产海尔电视机、海尔空调等,TCL工厂可以生产TCL电视机

3、、TCL空调等,相同品牌的电器构成了一个产品族,而相同类型的电器构成了一个产品等级结构,试使用抽象工厂模式模拟该环境。实例类图:ElectricalFactory+CreateTV() : TV+CreateAir_conditioning() : Air_conditioningHaierElectricalFactory+CreateTV() : TV+CreateAir_conditioning() : Air_conditioningTCLElectricalFactory+CreateTV() : TV+CreateAir_conditioning() : Air_condition

4、ingHaierAir_conditioning+Display() : voidTCLAir_conditioning+Display() : voidHaierTV+Display() : voidTCLTV+Display() : voidAir_conditioning+Display() : voidTV+Display() : voidClient上图中,ElectricalFactory接口充当抽象工厂,其子类HaierElectricalFactory和TCLElectricalFactory充当具体工厂,接口Air_conditioning和TV充当抽象产品,其子类Haier

5、Air_conditionin、TCLAir_conditioning、HaierTV和TCLTV充当具体产品。第六章 建造者模式4、计算机组装工厂可以将CPU、内存、硬盘、主机、显示器等硬件设备组装在一起构成一台完整的计算机,且构成的计算机可以是笔记本,也可以是台式机,还可以是不提供显示器的服务器主机。对于用户而言,无须关心计算机的组成设备和组装过程,工厂返回给用户的。是完整的计算机对象,使用建造者模式实现计算机组装过程,要求绘制类图并使用C#代码编程模拟实现。实例类图:Part- type - cpu - memory - disk - hostComputer - display + T

6、ype + CPU + Memory + Disk + HostComputer + Display + set_Type (string value) + get_Type ( ) + set_CPU (string value) + get_CPU ( ) + set_Memory (string value) + get_Memory ( ) + set_Disk (string value) + get_Disk ( ) + set_HosyComputer (string value) + get_HostComputer ( ) + set_Display (string valu

7、e) + get_Display ( ) : string: string: string: string: string: string: string: string: string: string: string: string: void: string: void: string: void: string: void: string: void: string: void: stringComputerPartBuilder abstract # computer Computer = new Computer()+ BuildType()+ BuildCPU()+ BuildMe

8、mory()+ BuildDisk()+ BuildHostComputer()+ BuildDisplay()+ CreateComputer(): void: void: void: void: void: void: ComputerComputerAssemble+ Construct(ComputerPartBuilder ab) : ComputerNoteBookBuilder+ BuildType()+ BuildCPU()+ BuildMemory()+ BuildDisk()+ BuildHostComputer()+ BuildDisplay(): void: void:

9、 void: void: void: voidPCBulider+ BuildType()+ BuildCPU()+ BuildMemory()+ BuildDisk()+ BuildHostComputer()+ BuildDisplay(): void: void: void: void: void: voidServerBulider+ BuildType()+ BuildCPU()+ BuildMemory()+ BuildDisk()+ BuildHostComputer()+ BuildDisplay(): void: void: void: void: void: void上图中

10、,ComputerAssemble 充当指挥者,ComputerPartBuilder 充当抽象建造者,NoteBookBuilder、PCBulider和ServerBulider充当具体建造者,Part充当复杂产品。第八章 单例模式6、使用MS Visual Studio设计一个多文档窗口(MDI),然后创建一个工具栏(ToolStrip),在工具栏中添加一个按钮,单击该按钮会弹出一个“工具”窗口,使用单例模式进行设计,使得“工具”窗口只能弹出一个,如图86所示:实例类图:ToolStrip- Strip : ToolStrip = null- Mini_Tool : ArrayList

11、= null-ToolStrip()+ GetToolStrip() :ToolStrip+ AddTool (string Tool) :void+ RemoveTool (string Tool) :void+ GetTool() :string上图中,将工具栏ToolStrip设计为单例角色,其中包含一个工具的集合Mini_Tool,每次在Mini_Tool中随机选择一个小工具来相应按钮的请求。第十章 桥接模式5、空客(Airbus)、波音(Boeing)和麦道(McDonnell-Douglas)都是飞机制造商,它们都生产载客飞机(Passenger Plane)和载货飞机(Cargo

12、 Plane)。试设计一个系统,描述这些飞机制造商以及它们所制造的飞机种类。实例类图:PlaneTypePlane+ DoPlane(PlaneType p): voidPassengerPlane+ DoPlane(PlaneType p): voidCargoPlane+ DoPlane(PlaneType p): voidManufacturerabstract# plane: Plane+ SetPlane(Plane plane): void+ PrasePlane(string PlaneName): voidAirbusManufacturer+ PrasePlane(strin

13、g PlaneName): voidBoeingManufacturer+ PrasePlane(string PlaneName): voidMcDonnell_DouglasManufacturer+ PrasePlane(string PlaneName): voidplane上图中,Manufacturer充当抽象类,其子类AirbusManufacturer、BoeingManufacturer和McDonnell_DouglasManufacturer充当扩充抽象类;Plane充当实现类接口,其子类CargoPlane和PassengerPlane充当具体实现类。6、某软件公司要开

14、发一个数据转换工具,可以将数据库中的数据转换成多种文件格式,例如TXT、XML、PDF等格式,同时该工具需要支持多种不同的数据库。试使用桥接模式对其进行设计,并使用C#代码编程模拟实现。实例类图:Dataabstract# formats:Dataformats+ SetDataformats(Dataformats formats): void+ ParseFile(string fileName): voidAccessData+ ParseFile(string fileName): voidSQLData+ ParseFile(string fileName): voidContent

15、Dataformats+ DoContent(Content c): void:: voidTXTformats+ DoPlane(Content c): voidPDFformats+ DoPlane(Content c): voidXMLPDFformats+ DoPlane(Content c): void+ PrasePlane(string PlaneName): voidformats上图中,Data充当抽象类,其子类AccessData、和SQLData充当扩充抽象类;Dataformats充当实现类接口,其子类PDFformats、XMLformats和TXTformats充当

16、具体实现类。第十一章 组合模式5、某教育机构的组织结构如图11-8所示:在该教育机构OA系统中可以给各级办公室下发公文,现采用组合模式设计该机构的组织结构,绘制相应的类图并使用C#语言编程模拟实现,在客户端代码中模拟下发公文。实例类图:officeListDocument abstract +Add( Document file ) : void+Remove(Document file) : void+GetChild(int i) : Abstract +IssuedDocument() : voidHeadquarters-document : string +Headquarters(

17、string document) : void +Add( Document file ) : void+Remove(Document file) : void+GetChild(int i) : Abstract +IssuedDocument() : voidBranch-document : string + Branch (string document) : void +Add( Document file ) : void+Remove(Document file) : void+GetChild(int i) :Abstract +IssuedDocument() : void

18、TeachingPoints1-document : string + TeachingPoints1(string document) : void +Add( Document file ) : void+Remove(Document file) : void+GetChild(int i) : Abstract +IssuedDocument() : voidTeachingPoints2-document : string + TeachingPoints2(string document) : void +Add( Document file ) : void+Remove(Doc

19、ument file) : void+GetChild(int i) : Abstract +IssuedDocument() : voidOffice-officeList : List-document : string + Office (string document) : void +Add( Document file ) : void+Remove(Document file) : void+GetChild(int i) :Abstract +IssuedDocument() : void上图中,Document充当抽象构件类,Office充当容器构件类,Headquarter

20、s、Branch、TeachingPoints1和TeachingPoints2充当叶子构件类。第十二章 装饰模式4、最简单的手机(SimplePhone)在接受到来电的时候,会发出声音提醒主人,现在需要为该手机添加一项功能,即在接收到来电的时候,除了有声音还能产生振动(JarPhone),还可以得到更加高级的手机(ComplexPhone),来电时它不仅能够发声,产生振动,而且有灯光闪烁提示。现用装饰模式来模拟手机功能的升级过程,要求绘制类图并使用C#语言模拟实现。实例类图:SimplePhone abstract+Display() : voidRingPhone+Display() :

21、voidComplexPhone-complex : SimplePhone+ComplexPhone( SimplePhone )+Display() : voidJarPhone+JarPhone( SImplePhone complex )+Display() : void+SetJarPhonr() : voidFlashLight+FlashLight ( SImplePhone complex )+Display() : void+SetFlashLight() : void上图中,SimplePhone充当抽象构建类,其子类RingPhone充当具体构建类,SimplePhone类的另一个子类ComplexPhone充当抽象装饰类,ComplexPhone的子类JarPhone和FlashLight充当具体装饰类。THANKS !致力为企业和个人提供合同协议,策划案计划书,学习课件等等打造全网一站式需求欢迎您的下载,资料仅供参考-可编辑修改-

展开阅读全文
相似文档                                   自信AI助手自信AI助手
猜你喜欢                                   自信AI导航自信AI导航
搜索标签

当前位置:首页 > 包罗万象 > 大杂烩

移动网页_全站_页脚广告1

关于我们      便捷服务       自信AI       AI导航        获赠5币

©2010-2024 宁波自信网络信息技术有限公司  版权所有

客服电话:4008-655-100  投诉/维权电话:4009-655-100

gongan.png浙公网安备33021202000488号   

icp.png浙ICP备2021020529号-1  |  浙B2-20240490  

关注我们 :gzh.png    weibo.png    LOFTER.png 

客服