欢迎来到冰豆网! | 帮助中心 分享价值,成长自我!
冰豆网
全部分类
  • IT计算机>
  • 经管营销>
  • 医药卫生>
  • 自然科学>
  • 农林牧渔>
  • 人文社科>
  • 工程科技>
  • PPT模板>
  • 求职职场>
  • 解决方案>
  • 总结汇报>
  • 党团工作>
  • ImageVerifierCode 换一换
    首页 冰豆网 > 资源分类 > DOCX文档下载
    分享到微信 分享到微博 分享到QQ空间

    肖正文抽象工厂模式.docx

    • 资源ID:4311482       资源大小:78.33KB        全文页数:20页
    • 资源格式: DOCX        下载积分:3金币
    快捷下载 游客一键下载
    账号登录下载
    微信登录下载
    三方登录下载: 微信开放平台登录 QQ登录
    二维码
    微信扫一扫登录
    下载资源需要3金币
    邮箱/手机:
    温馨提示:
    快捷下载时,用户名和密码都是您填写的邮箱或者手机号,方便查询和重复下载(系统自动生成)。
    如填写123,账号就是123,密码也是123。
    支付方式: 支付宝    微信支付   
    验证码:   换一换

    加入VIP,免费下载
     
    账号:
    密码:
    验证码:   换一换
      忘记密码?
        
    友情提示
    2、PDF文件下载后,可能会被浏览器默认打开,此种情况可以点击浏览器菜单,保存网页到桌面,就可以正常下载了。
    3、本站不支持迅雷下载,请使用电脑自带的IE浏览器,或者360浏览器、谷歌浏览器下载即可。
    4、本站资源下载后的文档和图纸-无水印,预览文档经过压缩,下载后原文更清晰。
    5、试题试卷类文档,如果标题没有明确说明有答案则都视为没有答案,请知晓。

    肖正文抽象工厂模式.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; /为商店配置一个配置方案


    注意事项

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

    温馨提示:如果因为网速或其他原因下载失败请重新下载,重复下载不扣分。




    关于我们 - 网站声明 - 网站地图 - 资源地图 - 友情链接 - 网站客服 - 联系我们

    copyright@ 2008-2022 冰点文档网站版权所有

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

    收起
    展开