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

上传人:b****1 文档编号:5127651 上传时间:2023-05-04 格式:DOCX 页数:25 大小:319.87KB
下载 相关 举报
面向对象系统分析和设计综合实验报告3Word文件下载.docx_第1页
第1页 / 共25页
面向对象系统分析和设计综合实验报告3Word文件下载.docx_第2页
第2页 / 共25页
面向对象系统分析和设计综合实验报告3Word文件下载.docx_第3页
第3页 / 共25页
面向对象系统分析和设计综合实验报告3Word文件下载.docx_第4页
第4页 / 共25页
面向对象系统分析和设计综合实验报告3Word文件下载.docx_第5页
第5页 / 共25页
面向对象系统分析和设计综合实验报告3Word文件下载.docx_第6页
第6页 / 共25页
面向对象系统分析和设计综合实验报告3Word文件下载.docx_第7页
第7页 / 共25页
面向对象系统分析和设计综合实验报告3Word文件下载.docx_第8页
第8页 / 共25页
面向对象系统分析和设计综合实验报告3Word文件下载.docx_第9页
第9页 / 共25页
面向对象系统分析和设计综合实验报告3Word文件下载.docx_第10页
第10页 / 共25页
面向对象系统分析和设计综合实验报告3Word文件下载.docx_第11页
第11页 / 共25页
面向对象系统分析和设计综合实验报告3Word文件下载.docx_第12页
第12页 / 共25页
面向对象系统分析和设计综合实验报告3Word文件下载.docx_第13页
第13页 / 共25页
面向对象系统分析和设计综合实验报告3Word文件下载.docx_第14页
第14页 / 共25页
面向对象系统分析和设计综合实验报告3Word文件下载.docx_第15页
第15页 / 共25页
面向对象系统分析和设计综合实验报告3Word文件下载.docx_第16页
第16页 / 共25页
面向对象系统分析和设计综合实验报告3Word文件下载.docx_第17页
第17页 / 共25页
面向对象系统分析和设计综合实验报告3Word文件下载.docx_第18页
第18页 / 共25页
面向对象系统分析和设计综合实验报告3Word文件下载.docx_第19页
第19页 / 共25页
面向对象系统分析和设计综合实验报告3Word文件下载.docx_第20页
第20页 / 共25页
亲,该文档总共25页,到这儿已超出免费预览范围,如果喜欢就下载吧!
下载资源
资源描述

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

《面向对象系统分析和设计综合实验报告3Word文件下载.docx》由会员分享,可在线阅读,更多相关《面向对象系统分析和设计综合实验报告3Word文件下载.docx(25页珍藏版)》请在冰点文库上搜索。

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

2)重构过程中所使用的面向对象设计原则及简要说明:

开闭原则:

创建新图形只要新加入图形工厂和对应图形类,不修改源代码。

依赖倒转原则:

针对接口编程。

单一职责原则:

每个工厂只生产对应图形。

2.某销售管理系统支持多种支付方式,如现金支付、行用卡支付和代金券支付等,我们可能会像下面这么写,考虑用简单工厂模式对其进行重构。

1)类图

2)实现代码:

publicclassClient{

publicstaticvoidmain(String[]args){

IpayFactoryiFactory=newIpayFactory();

Ipaymethonpaymethon=iFactory.createPaymethon("

cash"

);

if(paymethon!

=null){

paymethon.pay();

}else{

System.out.println("

error"

}

}

}

publicclassIpayFactory{

publicIpaymethoncreatePaymethon(Stringpaymethon)

{

if(paymethon.equalsIgnoreCase("

)){

returnnewCash();

elseif(paymethon.equalsIgnoreCase("

creditcard"

returnnewCreditCard();

voucher"

returnnewVoucher();

else{

returnnull;

publicinterfaceIpaymethon{

publicvoidpay();

publicclassCashimplementsIpaymethon{

publicvoidpay(){

System.out.println("

Cashpay"

publicclassCreditCardimplementsIpaymethon{

CreditCardpay"

publicclassVoucherimplementsIpaymethon{

Voucherpay"

3)实现结果:

3.使用简单工厂模式设计一个可以创建不同几何形状(Shape),如圆形(Circle)、矩形(Rectangle)和三角形(Triangle)等的绘图工具类,每个几何图形均具有绘制Draw()和擦除Erase()两个方法,要求在绘制不支持的几何图形时,抛出一个UnsupportedShapeException异常,绘制类图并编程模拟实现。

1)

类图

publicinterfaceShape{

publicvoiddraw();

publicvoiderase();

publicclassCircleimplementsShape{

publicvoiddraw(){

draw 

Circle"

publicvoiderase(){

erase 

publicclassRectangleimplementsShape{

Rectangle"

publicclassTriangleimplementsShape{

Triangle"

publicclassShapeFactory{

publicstaticShapeproduceShape(Stringshape)throwsUnsupportedShapeException{

if(shape.equals("

returnnewCircle();

elseif(shape.equals("

returnnewTriangle();

returnnewRectangle();

else{

thrownewUnsupportedShapeException();

publicclassUnsupportedShapeExceptionextendsException{

publicUnsupportedShapeException()

System.out.println("

绘制图形异常,请确认输入图形。

"

publicclassClient{

ShapeFactoryshapeFactory=newShapeFactory();

try{

shapeFactory.produceShape("

).draw();

).erase();

}catch(UnsupportedShapeExceptione){

e.printStackTrace();

4.现需要设计一个程序来读取多种不同类型的图片格式,针对每一种图片格式都设计一个图片读取器(ImageReader),如GIF图片读取器(GifReader)用于读取GIF格式的图片、JPG图片读取器(JpgReader)用于读取JPG格式的图片。

图片读取器对象通过图片读取器工厂ImageReaderFactory来创建,ImageReaderFactory是一个抽象类,用于定义创建图片读取器的工厂方法,其子类GifReaderFactory和JpgReaderFactory用于创建具体的图片读取器对象。

试使用工厂方法模式设计该程序,绘制类图并编程模拟实现。

需充分考虑系统的灵活性和可扩展性。

JpgReaderFactoryjFactory=newJpgReaderFactory();

jFactory.produceImageReader().readimage();

GifReaderFactorygFactory=newGifReaderFactory();

gFactory.produceImageReader().readimage();

publicinterfaceImageReader{

publicvoidreadimage();

publicclassGifReaderimplementsImageReader{

publicvoidreadimage(){

Readgifimage."

publicclassJpgReaderimplementsImageReader{

jpgreader"

Readjpgimage."

publicabstractclassImageReaderFactory{

publicabstractImageReaderproduceImageReader();

publicclassGifReaderFactoryextendsImageReaderFactory{

publicImageReaderproduceImageReader(){

gifreader"

returnnewGifReader();

publicclassJpgReaderFactoryextendsImageReaderFactory{

returnnewJpgReader();

5.有一个OEM制造商代理做HP笔记本电脑(Laptop),后来该制造商得到了更多的品牌笔记本电脑的订单Acer,Lenovo,Dell,该OEM商发现,如果一次同时做很多个牌子的本本,有些不利于管理。

利用工厂模式改善设计,绘制类图并编程模拟实现。

publicstaticvoidmain(String[]args){

IFactorylf=newHpFactory();

Laptoptp=lf.createLaptop();

tp.show();

lf=newAcerFactory();

tp=lf.createLaptop();

lf=newLenovoFactory();

lf=newDellFactory();

publicinterfaceIFactory{

publicLaptopcreateLaptop();

publicclassAcerFactoryimplementsIFactory{

publicLaptopcreateLaptop(){

returnnewAcerLaptop();

publicclassDellFactoryimplementsIFactory{

returnnewDellLaptop();

publicclassHpFactoryimplementsIFactory{

returnnewHpLaptop();

publicclassLenovoFactoryimplementsIFactory{

returnnewLenovoLaptop();

publicabstractclassLaptop{

publicvoidshow(){};

publicclassAcerLaptopextendsLaptop{

publicvoidshow(){

AcerLaptop"

publicclassDellLaptopextendsLaptop{

DellLaptop"

publicclassHpLaptopextendsLaptop{

HpLaptop"

publicclassLenovoLaptopextendsLaptop{

LenovoLaptop"

6.某软件公司欲开发一套界面皮肤库,可以对桌面软件进行界面美化。

不同的皮肤将提供视觉效果不同的按钮、文本框、组合框等界面元素,其结构如下图所示:

该皮肤库需要具备良好的灵活性和可扩展性,用户可以自由选择不同的皮肤,开发人员可以在不修改既有代码的基础上增加新的皮肤。

试使用抽象工厂模式设计该皮肤库,绘制类图并编程模拟实现。

SpringSkinFactoryskinFactory=newSpringSkinFactory();

skinFactory.createButton().action();

skinFactory.createTextbox().action();

skinFactory.createCombobox().action();

publicinterfaceSkinFactory{

publicAbstractButtoncreateButton();

publicAbstractTextboxcreateTextbox();

publicAbstractComboboxcreateCombobox();

publicclassSpringSkinFactoryimplementsSkinFactory{

publicAbstractButtoncreateButton(){

生成greenbutton"

returnnewGreenButton();

publicAbstractTextboxcreateTextbox(){

生成greentextbox"

returnnewGreenTextbox();

publicAbstractComboboxcreateCombobox(){

生成greencombobox"

returnnewGreenCombobox();

publicclassSummerSkinFactoryimplementsSkinFactory{

生成bluebutton"

returnnewBlueButton();

生成bluetextbox"

returnnewBlueTextbox();

生成bluecombobox"

returnnewBlueCombobox();

publicinterfaceAbstractButton{

publicvoidaction();

publicclassGreenButtonimplementsAbstractButton{

@Override

publicvoidaction(){

Greenbutton"

publicclassBlueButtonimplementsAbstractButton{

Bluebutton"

publicinterfaceAbstractTextbox{

publicclassGreenTextboximplementsAbstractTextbox{

GreenTextbox"

publicclassBlueTextboximplementsAbstractTextbox{

BlueTextbox"

publicinterfaceAbstractCombobox{

publicclassGreenComboboximplementsAbstractCombobox{

GreenCombobox"

publicclassBlueComboboximplementsAbstractCombobox{

BluCombobox"

7.麦当劳(McDonalds)和肯德基(KFC)快餐店都经营汉堡(Hamburg)和可乐(Cola),用控制台应用程序实现这两个快餐店经营产品的抽象工厂模式,并绘制该模式的UML图。

Hamburgh;

Colac;

AbstractFactoryaf=newMDNFactory();

h=af.createHamburg();

c=af.createCola();

h.getHumburg();

c.getCola();

af=newKDJFactory();

publicinterfaceAbstractFactory{

publicHamburgcreateHamburg();

publicColacreateCola();

publicclassKDJFactoryimplementsAbstractFactory{

publicHamburgcreateHamburg(){

returnnewKDJHamburg();

publicColacreateCola(){

returnnewKDJCola();

publ

展开阅读全文
相关资源
猜你喜欢
相关搜索
资源标签

当前位置:首页 > 工作范文 > 其它

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

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