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

上传人:jian****018 文档编号:8458430 上传时间:2020-03-29 格式:DOC 页数:8 大小:317.27KB
返回 下载 相关 举报
C#模式设计习题分析.doc_第1页
第1页 / 共8页
C#模式设计习题分析.doc_第2页
第2页 / 共8页
C#模式设计习题分析.doc_第3页
第3页 / 共8页
点击查看更多>>
资源描述
第三章 简单工厂模式5、使用简单工厂模式设计一个可以创建不同几何形状(Shape),如圆形(Circle)、矩形(Rectangle)和三角形(Triangle)等的绘图工具类,每个几何图形均具有回执Draw()和擦除Erase()两个方案,要求在绘制不支持的几何图形时,抛出一个UnsupportedShapeException异常,绘制类图并使用C#语言编程模拟实现Shape+Draw() : void+Erase() : voidShapeFactory+ShapeProduce(string type) : ShapeCircle+Draw() : void+Erase() : voidTriangle+Draw() : void+Erase() : voidRectangle+Draw() : void+Erase() : voidUnsupportedShapeException+UnsupportedShapeException() 实例类图:上图中,Shape接口充当抽象产品类,其子类Circle、Triangle、Rectangle和UnsupportedShapeException充当具体产品类,ShapeFactory充当工厂类。第五章 抽象工厂模式5、一个电器工厂可以生产多种类型的电器,如海尔工厂可以生产海尔电视机、海尔空调等,TCL工厂可以生产TCL电视机、TCL空调等,相同品牌的电器构成了一个产品族,而相同类型的电器构成了一个产品等级结构,试使用抽象工厂模式模拟该环境。实例类图:ElectricalFactory+CreateTV() : TV+CreateAir_conditioning() : Air_conditioningHaierElectricalFactory+CreateTV() : TV+CreateAir_conditioning() : Air_conditioningTCLElectricalFactory+CreateTV() : TV+CreateAir_conditioning() : Air_conditioningHaierAir_conditioning+Display() : voidTCLAir_conditioning+Display() : voidHaierTV+Display() : voidTCLTV+Display() : voidAir_conditioning+Display() : voidTV+Display() : voidClient上图中,ElectricalFactory接口充当抽象工厂,其子类HaierElectricalFactory和TCLElectricalFactory充当具体工厂,接口Air_conditioning和TV充当抽象产品,其子类HaierAir_conditionin、TCLAir_conditioning、HaierTV和TCLTV充当具体产品。第六章 建造者模式4、计算机组装工厂可以将CPU、内存、硬盘、主机、显示器等硬件设备组装在一起构成一台完整的计算机,且构成的计算机可以是笔记本,也可以是台式机,还可以是不提供显示器的服务器主机。对于用户而言,无须关心计算机的组成设备和组装过程,工厂返回给用户的。是完整的计算机对象,使用建造者模式实现计算机组装过程,要求绘制类图并使用C#代码编程模拟实现。实例类图:Part- type - cpu - memory - disk - hostComputer - display + Type + 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 value) + 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()+ BuildMemory()+ BuildDisk()+ BuildHostComputer()+ BuildDisplay()+ CreateComputer(): void: void: void: void: void: void: ComputerComputerAssemble+ Construct(ComputerPartBuilder ab) : ComputerNoteBookBuilder+ BuildType()+ BuildCPU()+ BuildMemory()+ BuildDisk()+ BuildHostComputer()+ BuildDisplay(): void: void: 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上图中,ComputerAssemble 充当指挥者,ComputerPartBuilder 充当抽象建造者,NoteBookBuilder、PCBulider和ServerBulider充当具体建造者,Part充当复杂产品。第八章 单例模式6、使用MS Visual Studio设计一个多文档窗口(MDI),然后创建一个工具栏(ToolStrip),在工具栏中添加一个按钮,单击该按钮会弹出一个“工具”窗口,使用单例模式进行设计,使得“工具”窗口只能弹出一个,如图86所示:实例类图:ToolStrip- Strip : ToolStrip = null- Mini_Tool : ArrayList = 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 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(string PlaneName): voidBoeingManufacturer+ PrasePlane(string PlaneName): voidMcDonnell_DouglasManufacturer+ PrasePlane(string PlaneName): voidplane上图中,Manufacturer充当抽象类,其子类AirbusManufacturer、BoeingManufacturer和McDonnell_DouglasManufacturer充当扩充抽象类;Plane充当实现类接口,其子类CargoPlane和PassengerPlane充当具体实现类。6、某软件公司要开发一个数据转换工具,可以将数据库中的数据转换成多种文件格式,例如TXT、XML、PDF等格式,同时该工具需要支持多种不同的数据库。试使用桥接模式对其进行设计,并使用C#代码编程模拟实现。实例类图:Dataabstract# formats:Dataformats+ SetDataformats(Dataformats formats): void+ ParseFile(string fileName): voidAccessData+ ParseFile(string fileName): voidSQLData+ ParseFile(string fileName): voidContentDataformats+ 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充当具体实现类。第十一章 组合模式5、某教育机构的组织结构如图11-8所示:在该教育机构OA系统中可以给各级办公室下发公文,现采用组合模式设计该机构的组织结构,绘制相应的类图并使用C#语言编程模拟实现,在客户端代码中模拟下发公文。实例类图:officeListDocument abstract +Add( Document file ) : void+Remove(Document file) : void+GetChild(int i) : Abstract +IssuedDocument() : voidHeadquarters-document : string +Headquarters(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() : voidTeachingPoints1-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(Document 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充当容器构件类,Headquarters、Branch、TeachingPoints1和TeachingPoints2充当叶子构件类。第十二章 装饰模式4、最简单的手机(SimplePhone)在接受到来电的时候,会发出声音提醒主人,现在需要为该手机添加一项功能,即在接收到来电的时候,除了有声音还能产生振动(JarPhone),还可以得到更加高级的手机(ComplexPhone),来电时它不仅能够发声,产生振动,而且有灯光闪烁提示。现用装饰模式来模拟手机功能的升级过程,要求绘制类图并使用C#语言模拟实现。实例类图:SimplePhone abstract+Display() : voidRingPhone+Display() : 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充当具体装饰类。
展开阅读全文
相关资源
相关搜索

当前位置:首页 > 建筑环境 > 建筑工程


copyright@ 2023-2025  zhuangpeitu.com 装配图网版权所有   联系电话:18123376007

备案号:ICP2024067431-1 川公网安备51140202000466号


本站为文档C2C交易模式,即用户上传的文档直接被用户下载,本站只是中间服务平台,本站所有文档下载所得的收益归上传人(含作者)所有。装配图网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。若文档所含内容侵犯了您的版权或隐私,请立即通知装配图网,我们立即给予删除!