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

加入VIP,免费下载
 

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

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

下载须知

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

版权提示 | 免责声明

本文(肖正文抽象工厂模式.docx)为本站会员(b****3)主动上传,冰豆网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。 若此文所含内容侵犯了您的版权或隐私,请立即通知冰豆网(发送邮件至service@bdocx.com或直接QQ联系客服),我们立即给予删除!

肖正文抽象工厂模式.docx

1、肖正文抽象工厂模式云南大学软件学院实 验 报 告序号: 姓名: 肖正文 学号: 20121120141 专业:软件工程 日期:2014/12/18成绩: 实验三 抽象工厂模式的运用一、实验目的: 抽象工厂模式提供一个接口,用于创建相关或依赖对象的家族,而不需要明确指定具体类。在熟悉抽象工厂模式相关理论知识的基础上,使用抽象工厂模式实现“电脑配置商店”程序。二、实验要求:使用抽象工厂模式实现“电脑配置商店”,要求如下:1. 电脑由CPU、主板、显卡、内存、硬盘等配件组合而成。现电脑配置有两种配置方案。2. 根据配置方案可以显示具体配置信息。3. 根据配置方案可以显示价格。1、 设计并绘制该程序的

2、类图;2、 依照设计的类图使用Java语言编写代码,并实现该程序;3、 除了核心的模式相关类实现外,提供测试环境,按照难度高低,分别是:a) 控制台程序,Client硬编码初始化模式和测试环境,运行结果文本输出;b) 控制台程序,Client初始化测试环境,并根据用户输入运算,运行结果文本输出;c) 设计并实现用户UI,Client初始化测试环境,并根据用户在UI控件上的输入运算,运行结果文本输出;三、实验内容:1类图2被装饰类package xiao.it.abGoods;/* * 抽象的产品类 */import xiao.it.ComIngredient.*;public abstract

3、 class Computer protected String name = null; protected CPU cpu = null; protected HardDisk hardd = null; protected MasterBord mb = null; protected NVIDIA nvidia = null; protected RAM ram = null; / 抽象的产品准备方法 public abstract void Prepare(); public String getName() return name; public void setName(Stri

4、ng name) this.name = name; /* * 显示电脑的配置信息 */ public String showInfo() return this.name +n+ this.cpu.getDesc()+n + this.hardd.getDesc() +n+ this.mb.getDesc() +n+ this.nvidia.getDesc()+n + this.ram.getDesc(); /* * 显示电脑的花费价钱 */ public double showCost() return this.cpu.getCost()+this.hardd.getCost()+thi

5、s.mb.getCost()+this.nvidia.getCost()+this.ram.getCost(); package xiao.it.abFactor;/* * 抽象工厂 */import xiao.it.ComIngredient.*; public interface ComputerIngredientFactory public CPU createCUP(); public HardDisk createHardD(); public MasterBord createMasterB(); public NVIDIA createNV(); public RAM crea

6、teR();具体工厂package xiao.it.conFactor;/* * Dura原料工场 */import xiao.it.ComIngredient.CPU;import xiao.it.ComIngredient.HardDisk;import xiao.it.ComIngredient.MasterBord;import xiao.it.ComIngredient.NVIDIA;import xiao.it.ComIngredient.RAM;import xiao.it.abFactor.ComputerIngredientFactory; public class Dura

7、Factor implements ComputerIngredientFactory Override public CPU createCUP() return new CPU(duraCUP 2.5HZ,1200); Override public HardDisk createHardD() / TODO Auto-generated method stub return new HardDisk(duraDisk 750G,400); Override public MasterBord createMasterB() / TODO Auto-generated method stu

8、b return new MasterBord(duraMb,1600); Override public NVIDIA createNV() / TODO Auto-generated method stub return new NVIDIA(duraNVIDIA 610*2MB, 600); Override public RAM createR() / TODO Auto-generated method stub return new RAM(duraRAM 2G, 300); package xiao.it.conFactor;import xiao.it.ComIngredien

9、t.CPU;import xiao.it.ComIngredient.HardDisk;import xiao.it.ComIngredient.MasterBord;import xiao.it.ComIngredient.NVIDIA;import xiao.it.ComIngredient.RAM;import xiao.it.abFactor.ComputerIngredientFactory;/* * intel原料工场 * author Administrator * */public class IntelFactor implements ComputerIngredientF

10、actory Override public CPU createCUP() CPU c=new CPU(intelduraCUP 3.1HZ, 1600); return c; Override public HardDisk createHardD() / TODO Auto-generated method stub return new HardDisk(IntelDisk 1T,400); Override public MasterBord createMasterB() / TODO Auto-generated method stub return new MasterBord

11、(IntelduraMb,1600); Override public NVIDIA createNV() / TODO Auto-generated method stub return new NVIDIA(intelNVIDIA 500*2MB, 600); Override public RAM createR() / TODO Auto-generated method stub return new RAM(intelRAM 4G, 500); 具体被装饰者package xiao.it.conGoods;import xiao.it.abFactor.ComputerIngred

12、ientFactory;import xiao.it.abGoods.Computer;public class HongJi extends Computer ComputerIngredientFactory com=null; /为宏基电脑分配工厂 public HongJi(ComputerIngredientFactory com) =com; /用特定的工厂来为宏基配置 Override public void Prepare() cpu=com.createCUP(); hardd=com.createHardD(); mb=com.createMasterB(); nvidia

13、=com.createNV(); ram=com.createR(); package xiao.it.conGoods;/* * 华硕电脑 */import xiao.it.abFactor.ComputerIngredientFactory;import xiao.it.abGoods.Computer;public class HuaShuo extends Computer ComputerIngredientFactory com=null; /为华硕电脑分配工厂 public HuaShuo(ComputerIngredientFactory com) =com; /用特定的工厂来

14、为宏基配置 Override public void Prepare() cpu=com.createCUP(); hardd=com.createHardD(); mb=com.createMasterB(); nvidia=com.createNV(); ram=com.createR(); package xiao.it.conGoods;import xiao.it.abFactor.ComputerIngredientFactory;import xiao.it.abGoods.Computer;public class LianXiang extends Computer Comp

15、uterIngredientFactory com=null; /为联想电脑分配工厂 public LianXiang(ComputerIngredientFactory com) =com; /用特定的工厂来为宏基配置 Override public void Prepare() cpu=com.createCUP(); hardd=com.createHardD(); mb=com.createMasterB(); nvidia=com.createNV(); ram=com.createR(); 原料类package xiao.it.ComIngredient;/* * cpu * au

16、thor Administrator * */public class CPU private String desc; private double cost; public String getDesc() return desc; public void setDesc(String desc) this.desc = desc; public double getCost() return cost; public void setCost(double cost) this.cost = cost; public CPU(String desc, double cost) super

17、(); this.desc = desc; this.cost = cost; package xiao.it.ComIngredient;/* * 硬盘 * author Administrator * */public class HardDisk private String desc; private double cost; public String getDesc() return desc; public void setDesc(String desc) this.desc = desc; public double getCost() return cost; public

18、 void setCost(double cost) this.cost = cost; public HardDisk(String desc, double cost) super(); this.desc = desc; this.cost = cost; package xiao.it.ComIngredient;/* * 主板 * author Administrator * */public class MasterBord private String desc; private double cost; public String getDesc() return desc;

19、public void setDesc(String desc) this.desc = desc; public double getCost() return cost; public void setCost(double cost) this.cost = cost; public MasterBord(String desc, double cost) super(); this.desc = desc; this.cost = cost; package xiao.it.ComIngredient;/* * 显卡 * author Administrator * */public

20、class NVIDIA private String desc; private double cost; public String getDesc() return desc; public void setDesc(String desc) this.desc = desc; public double getCost() return cost; public void setCost(double cost) this.cost = cost; public NVIDIA(String desc, double cost) super(); this.desc = desc; th

21、is.cost = cost; package xiao.it.ComIngredient;public class RAM private String desc; private double cost; public String getDesc() return desc; public void setDesc(String desc) this.desc = desc; public double getCost() return cost; public void setCost(double cost) this.cost = cost; public RAM(String d

22、esc, double cost) super(); this.desc = desc; this.cost = cost; 商店类package xiao.it.abGoodsStore;/* * 电脑商城 */import xiao.it.abGoods.Computer;public abstract class ComputerStor public Computer orderC(String type) Computer c=null; c=CreateComputer(type); return c; /抽象方法去创建电脑交给子类 protected abstract Compu

23、ter CreateComputer(String type);package xiao.it.conGoodsStore;/* * 贵州商城 */import xiao.it.abFactor.ComputerIngredientFactory;import xiao.it.abGoods.Computer;import xiao.it.abGoodsStore.ComputerStor;import xiao.it.conFactor.IntelFactor;import xiao.it.conGoods.HongJi;import xiao.it.conGoods.HuaShuo;imp

24、ort xiao.it.conGoods.LianXiang;public class GZStore extends ComputerStor ComputerIngredientFactory factory = null; /为商店配置一个配置方案 public GZStore(ComputerIngredientFactory fa) this.factory=fa; Override protected Computer CreateComputer(String type) Computer c = null; / intel的配置方案 / TODO Auto-generated

25、method stub if (type.equals(宏基) c = new HongJi(factory); c.setName(宏基电脑); else if (type.equals(华硕) c = new HuaShuo(factory); c.setName(华硕电脑); else if (type.equals(联想) c = new LianXiang(factory); c.setName(联想电脑); return c; package xiao.it.conGoodsStore;/* * 四川商城 */import xiao.it.abFactor.ComputerIngr

26、edientFactory;import xiao.it.abGoods.Computer;import xiao.it.abGoodsStore.ComputerStor;import xiao.it.conFactor.IntelFactor;import xiao.it.conGoods.HongJi;import xiao.it.conGoods.HuaShuo;import xiao.it.conGoods.LianXiang;public class SCStore extends ComputerStor ComputerIngredientFactory factory = n

27、ull; /为商店配置一个配置方案 public SCStore(ComputerIngredientFactory fa) this.factory=fa; Override protected Computer CreateComputer(String type) Computer c = null; / TODO Auto-generated method stub if (type.equals(宏基) c = new HongJi(factory); c.setName(宏基电脑); else if (type.equals(华硕) c = new HuaShuo(factory)

28、; c.setName(华硕电脑); else if (type.equals(联想) c = new LianXiang(factory); c.setName(联想电脑); return c; package xiao.it.conGoodsStore;/* * 云南商城 */import xiao.it.abFactor.ComputerIngredientFactory;import xiao.it.abGoods.Computer;import xiao.it.abGoodsStore.ComputerStor;import xiao.it.conFactor.IntelFactor;import xiao.it.conGoods.*;public class YNStore extends ComputerStor ComputerIngredientFactory factory = null; /为商店配置一个配置方案

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1