ImageVerifierCode 换一换
格式:DOCX , 页数:25 ,大小:319.87KB ,
资源ID:5127651      下载积分:1 金币
快捷下载
登录下载
邮箱/手机:
温馨提示:
快捷下载时,用户名和密码都是您填写的邮箱或者手机号,方便查询和重复下载(系统自动生成)。 如填写123,账号就是123,密码也是123。
特别说明:
请自助下载,系统不会自动发送文件的哦; 如果您已付费,想二次下载,请登录后访问:我的下载记录
支付方式: 支付宝    微信支付   
验证码:   换一换

加入VIP,免费下载
 

温馨提示:由于个人手机设置不同,如果发现不能下载,请复制以下地址【https://www.bingdoc.com/d-5127651.html】到电脑端继续下载(重复下载不扣费)。

已注册用户请登录:
账号:
密码:
验证码:   换一换
  忘记密码?
三方登录: 微信登录   QQ登录  

下载须知

1: 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。
2: 试题试卷类文档,如果标题没有明确说明有答案则都视为没有答案,请知晓。
3: 文件的所有权益归上传用户所有。
4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
5. 本站仅提供交流平台,并不能对任何下载内容负责。
6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

版权提示 | 免责声明

本文(面向对象系统分析和设计综合实验报告3Word文件下载.docx)为本站会员(b****1)主动上传,冰点文库仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。 若此文所含内容侵犯了您的版权或隐私,请立即通知冰点文库(发送邮件至service@bingdoc.com或直接QQ联系客服),我们立即给予删除!

面向对象系统分析和设计综合实验报告3Word文件下载.docx

1、2)重构过程中所使用的面向对象设计原则及简要说明:开闭原则:创建新图形只要新加入图形工厂和对应图形类,不修改源代码。依赖倒转原则:针对接口编程。单一职责原则:每个工厂只生产对应图形。2. 某销售管理系统支持多种支付方式,如现金支付、行用卡支付和代金券支付等,我们可能会像下面这么写,考虑用简单工厂模式对其进行重构。1)类图2)实现代码:public class Client public static void main(String args) IpayFactory iFactory = new IpayFactory(); Ipaymethon paymethon = iFactory.c

2、reatePaymethon(cash); if (paymethon != null) paymethon.pay(); else System.out.println(error public class IpayFactory public Ipaymethon createPaymethon(String paymethon) if (paymethon.equalsIgnoreCase() return new Cash(); else if (paymethon.equalsIgnoreCase(creditcard return new CreditCard();voucher

3、return new Voucher(); else return null;public interface Ipaymethon public void pay();public class Cash implements Ipaymethon public void pay() System.out.println(Cash paypublic class CreditCard implements Ipaymethon CreditCard paypublic class Voucher implements Ipaymethon Voucher pay3)实现结果:3使用简单工厂模式

4、设计一个可以创建不同几何形状(Shape),如圆形(Circle)、矩形(Rectangle)和三角形(Triangle)等的绘图工具类,每个几何图形均具有绘制Draw()和擦除Erase()两个方法,要求在绘制不支持的几何图形时,抛出一个UnsupportedShapeException异常,绘制类图并编程模拟实现。1)类图public interface Shape public void draw(); public void erase();public class Circle implements Shape public void draw()drawCircle public

5、void erase()erasepublic class Rectangle implements Shape Rectanglepublic class Triangle implements Shape Trianglepublic class ShapeFactory public static Shape produceShape(String shape) throws UnsupportedShapeException if (shape.equals( return new Circle(); else if (shape.equals( return new Triangle

6、(); return new Rectangle(); else throw new UnsupportedShapeException();public class UnsupportedShapeException extends Exception public UnsupportedShapeException () System.out.println(绘制图形异常,请确认输入图形。 public class Client ShapeFactory shapeFactory=new ShapeFactory(); try shapeFactory.produceShape().dra

7、w();).erase(); catch (UnsupportedShapeException e) e.printStackTrace();4. 现需要设计一个程序来读取多种不同类型的图片格式,针对每一种图片格式都设计一个图片读取器(ImageReader),如GIF图片读取器(GifReader)用于读取GIF格式的图片、JPG图片读取器(JpgReader)用于读取JPG格式的图片。图片读取器对象通过图片读取器工厂ImageReaderFactory来创建,ImageReaderFactory是一个抽象类,用于定义创建图片读取器的工厂方法,其子类GifReaderFactory和JpgR

8、eaderFactory用于创建具体的图片读取器对象。试使用工厂方法模式设计该程序,绘制类图并编程模拟实现。需充分考虑系统的灵活性和可扩展性。 JpgReaderFactory jFactory = new JpgReaderFactory(); jFactory.produceImageReader().readimage(); GifReaderFactory gFactory = new GifReaderFactory(); gFactory.produceImageReader().readimage();public interface ImageReader public voi

9、d readimage();public class GifReader implements ImageReader public void readimage()Read gif image.public class JpgReader implements ImageReader jpg readerRead jpg image.public abstract class ImageReaderFactory public abstract ImageReader produceImageReader();public class GifReaderFactory extends Ima

10、geReaderFactory public ImageReader produceImageReader()gif reader return new GifReader();public class JpgReaderFactory extends ImageReaderFactory return new JpgReader();5. 有一个OEM制造商代理做HP笔记本电脑(Laptop),后来该制造商得到了更多的品牌笔记本电脑的订单Acer,Lenovo,Dell,该OEM商发现,如果一次同时做很多个牌子的本本,有些不利于管理。利用工厂模式改善设计,绘制类图并编程模拟实现。 publi

11、c static void main(String args) IFactory lf = new HpFactory(); Laptop tp = lf.createLaptop(); tp.show(); lf = new AcerFactory(); tp = lf.createLaptop(); lf = new LenovoFactory(); lf = new DellFactory();public interface IFactory public Laptop createLaptop();public class AcerFactory implements IFactor

12、y public Laptop createLaptop() return new AcerLaptop();public class DellFactory implements IFactory return new DellLaptop();public class HpFactory implements IFactory return new HpLaptop();public class LenovoFactory implements IFactory return new LenovoLaptop();public abstract class Laptop public vo

13、id show();public class AcerLaptop extends Laptop public void show()AcerLaptoppublic class DellLaptop extends Laptop DellLaptoppublic class HpLaptop extends Laptop HpLaptoppublic class LenovoLaptop extends Laptop LenovoLaptop6. 某软件公司欲开发一套界面皮肤库,可以对桌面软件进行界面美化。不同的皮肤将提供视觉效果不同的按钮、文本框、组合框等界面元素,其结构如下图所示:该皮肤

14、库需要具备良好的灵活性和可扩展性,用户可以自由选择不同的皮肤,开发人员可以在不修改既有代码的基础上增加新的皮肤。试使用抽象工厂模式设计该皮肤库,绘制类图并编程模拟实现。 SpringSkinFactory skinFactory = new SpringSkinFactory(); skinFactory.createButton().action(); skinFactory.createTextbox().action(); skinFactory.createCombobox().action();public interface SkinFactory public AbstractB

15、utton createButton(); public AbstractTextbox createTextbox(); public AbstractCombobox createCombobox();public class SpringSkinFactory implements SkinFactory public AbstractButton createButton()生成 green button return new GreenButton(); public AbstractTextbox createTextbox()生成 green textbox return new

16、 GreenTextbox(); public AbstractCombobox createCombobox()生成 green combobox return new GreenCombobox();public class SummerSkinFactory implements SkinFactory 生成 blue button return new BlueButton();生成 blue textbox return new BlueTextbox();生成 blue combobox return new BlueCombobox();public interface Abst

17、ractButton public void action();public class GreenButton implements AbstractButton Override public void action() Green buttonpublic class BlueButton implements AbstractButton Blue buttonpublic interface AbstractTextbox public class GreenTextbox implements AbstractTextbox Green Textboxpublic class Bl

18、ueTextbox implements AbstractTextbox Blue Textboxpublic interface AbstractCombobox public class GreenCombobox implements AbstractCombobox Green Comboboxpublic class BlueCombobox implements AbstractCombobox Blu Combobox7. 麦当劳(McDonalds)和肯德基(KFC)快餐店都经营汉堡(Hamburg)和可乐(Cola),用控制台应用程序实现这两个快餐店经营产品的抽象工厂模式,并

19、绘制该模式的UML图。 Hamburg h; Cola c; AbstractFactory af = new MDNFactory(); h = af.createHamburg(); c = af.createCola(); h.getHumburg(); c.getCola(); af = new KDJFactory();public interface AbstractFactory public Hamburg createHamburg(); public Cola createCola();public class KDJFactory implements AbstractFactory public Hamburg createHamburg() return new KDJHamburg(); public Cola createCola() return new KDJCola();publ

copyright@ 2008-2023 冰点文库 网站版权所有

经营许可证编号:鄂ICP备19020893号-2