第一范文网 - 专业文章范例文档资料分享平台

面向对象系统分析和设计综合实验报告3

来源:用户分享 时间:2025/6/7 1:06:56 本文由loading 分享 下载这篇文档手机版
说明:文章内容仅供预览,部分内容可能不全,需要完整文档或者需要复制内容,请下载word后使用。下载word有问题请添加微信号:xxxxxxx或QQ:xxxxxx 处理(尽可能给您提供完整文档),感谢您的支持与谅解。

西南科技大学计算机学院 《面向对象系统分析和设计》实验报告

2) 实现代码:

public class Client {

public static void main(String[] args){ IFactory lf = new HpFactory(); Laptop tp = lf.createLaptop(); tp.show();

lf = new AcerFactory(); tp = lf.createLaptop(); tp.show();

lf = new LenovoFactory(); tp = lf.createLaptop(); tp.show();

lf = new DellFactory(); tp = lf.createLaptop(); tp.show(); }

}

public interface IFactory {

public Laptop createLaptop(); }

public class AcerFactory implements IFactory { public Laptop createLaptop(){ return new AcerLaptop(); } }

public class DellFactory implements IFactory {

9

西南科技大学计算机学院 《面向对象系统分析和设计》实验报告 public Laptop createLaptop(){ return new DellLaptop(); } }

public class HpFactory implements IFactory { public Laptop createLaptop(){ return new HpLaptop(); } }

public class LenovoFactory implements IFactory { public Laptop createLaptop(){ return new LenovoLaptop(); } }

public abstract class Laptop { public void show(){}; }

public class AcerLaptop extends Laptop { public void show(){

System.out.println(\); } }

public class DellLaptop extends Laptop { public void show(){

System.out.println(\); } }

public class HpLaptop extends Laptop { public void show(){

System.out.println(\); } }

public class LenovoLaptop extends Laptop { public void show(){

System.out.println(\);

10

西南科技大学计算机学院 《面向对象系统分析和设计》实验报告 } }

3) 实现结果:

6. 某软件公司欲开发一套界面皮肤库,可以对桌面软件进行界面美化。不同的皮肤将提供视觉效果不同的按钮、文本框、组合框等界面元素,其结构如下图所示:

浅绿色按钮Spring风格绿色边框文本框绿色边框组合框皮肤库浅蓝色按钮Summer风格蓝色边框文本框蓝色边框组合框 该皮肤库需要具备良好的灵活性和可扩展性,用户可以自由选择不同的皮肤,开发人员可以在不修改既有代码的基础上增加新的皮肤。试使用抽象工厂模式设计该皮肤库,绘制类图并编程模拟实现。

1) 类图

11

西南科技大学计算机学院 《面向对象系统分析和设计》实验报告

2) 实现代码:

public class Client {

public static void main(String[] args) {

SpringSkinFactory skinFactory = new SpringSkinFactory(); skinFactory.createButton().action(); skinFactory.createTextbox().action(); skinFactory.createCombobox().action(); }

}

public interface SkinFactory {

public AbstractButton createButton(); public AbstractTextbox createTextbox(); public AbstractCombobox createCombobox();

}

public class SpringSkinFactory implements SkinFactory { public AbstractButton createButton(){ System.out.println(\生成 green button\); return new GreenButton(); }

public AbstractTextbox createTextbox(){ System.out.println(\生成 green textbox\); return new GreenTextbox(); }

public AbstractCombobox createCombobox(){ System.out.println(\生成 green combobox\); return new GreenCombobox(); }

}

public class SummerSkinFactory implements SkinFactory { public AbstractButton createButton(){

System.out.println(\生成 blue button\); return new BlueButton();

12

面向对象系统分析和设计综合实验报告3.doc 将本文的Word文档下载到电脑,方便复制、编辑、收藏和打印
本文链接:https://www.diyifanwen.net/c7ut498d6ng0daes3y3831emx02sb8q00vm2_3.html(转载请注明文章来源)
热门推荐
Copyright © 2012-2023 第一范文网 版权所有 免责声明 | 联系我们
声明 :本网站尊重并保护知识产权,根据《信息网络传播权保护条例》,如果我们转载的作品侵犯了您的权利,请在一个月内通知我们,我们会及时删除。
客服QQ:xxxxxx 邮箱:xxxxxx@qq.com
渝ICP备2023013149号
Top