当前位置: 首页 > news >正文

网站app免费软件青岛网站建设谁家好一些

网站app免费软件,青岛网站建设谁家好一些,成都网站品牌设计策划,网站怎么建设可以发图评论文章目录 一、工厂模式#xff08;三种#xff09;1.简单工厂模式1.1 概念#xff1a;1.2 使用场景#xff1a;1.3 模型图解#xff1a;1.4 伪代码#xff1a; 2.工厂方法模式2.1 概念#xff1a;2.2 使用场景#xff1a;2.3 模型图解#xff1a;2.4 伪代码 3.抽象工厂… 文章目录 一、工厂模式三种1.简单工厂模式1.1 概念1.2 使用场景1.3 模型图解1.4 伪代码 2.工厂方法模式2.1 概念2.2 使用场景2.3 模型图解2.4 伪代码 3.抽象工厂模式3.1 概念3.2 使用场景3.3 模型图解以两层模型做例子3.4 伪代码3.4.1 以品牌角度设计工厂3.4.2 以手机角度设计工厂3.5 实战抽象工厂 简单工厂模式 策略模式3.5.1 业务方法调用3.5.2 抽象工厂创建二级工厂定义获取业务对象接口二级工厂去创建具体的业务对象3.5.3 二级工厂 获得对象3.5.3 二级工厂 具体的业务对象3.5.3 处理的业务 补充6大设计原则3.6 总结 一、工厂模式三种 1.简单工厂模式 1.1 概念 通过一个工厂类来创建对象根据不同的参数或条件返回相应的对象实例。 隐藏了对象的创建细节客户端只需通过工厂类获取对象而不需要直接实例化对象。 1.2 使用场景 使用者根据不同的参数或条件返回相应的对象实例 1.3 模型图解 角色手机总工厂、参数、手机、小米手机、华为手机 后续补充 1.4 伪代码 public class SimpleFactoryTest {static class SimpleFactory {static SimpleFactoryTest.Mobile createMobile(int mobileType) throws Exception {if (mobileType 1) {return new SimpleFactoryTest.HuaWei();} else if (mobileType 2) {return new SimpleFactoryTest.XiaoMi();} else {throw new Exception(手机类型不存在);}}}public static class Mobile {protected void call() {System.out.println(mobile...);}}public static class HuaWei extends Mobile {public void call() {System.out.println(huaWei...);}}public static class XiaoMi extends Mobile {public void call() {System.out.println(xiaomi...);}}public static void main(String[] args) throws Exception {SimpleFactoryTest.Mobile mobile SimpleFactory.createMobile(1);mobile.call();} }2.工厂方法模式 2.1 概念 定义了一个创建对象的接口具体对象的创建由对象工厂决定。 使得对象的创建延迟到子类工厂从而实现了对扩展开放、对修改关闭的原则。 2.2 使用场景 使用者根据不同的子工厂创建相应的对象实例 2.3 模型图解 角色手机总工厂、小米手机工厂、华为手机工厂、手机、小米手机、华为手机 后续补充 2.4 伪代码 public class FactoryMethodTest {interface FactoryMethod {Mobile createMobile();}static class HuaweiFactory implements FactoryMethod {Overridepublic Mobile createMobile() {return new Huawei();}}static class XiaomiFactory implements FactoryMethod {Overridepublic Mobile createMobile() {return new Xiaomi();}}static class Mobile {protected void call() {System.out.println(mobile...);}}static class Huawei extends Mobile {Overridepublic void call() {System.out.println(huawei...);}}static class Xiaomi extends Mobile {Overridepublic void call() {System.out.println(xiaomi...);}}public static void main(String[] args) {final HuaweiFactory huaweiFactory new HuaweiFactory();final Mobile mobile huaweiFactory.createMobile();mobile.call();} }3.抽象工厂模式 3.1 概念 抽象工厂模式提供一个接口用于创建一系列相关或相互依赖的对象。 通过使用抽象工厂及其产品接口来创建对象从而将客户端与具体的产品实现解耦。 3.2 使用场景 适用三层关系 产品品牌子品牌手机华为手机Mate60 / P60手机 …等手机小米手机红米 / Note2 手机 … 等 适用两层关系 产品品牌手机华为电脑小米 3.3 模型图解以两层模型做例子 角色总工厂、小米工厂、华为工厂、小米手机、华为手机、小米路由器、华为路由器 3.4 伪代码 3.4.1 以品牌角度设计工厂 /*** descr: 以品牌角度设计工厂** date: 2024/1/24**/ public interface AbstractFactory {Phone createPhone();Computer createComputer();class HuaweiFactory implements AbstractFactory {Overridepublic Phone createPhone() {return new HuaweiPhone();}Overridepublic Computer createComputer() {return new HuaweiComputer();}}class XiaomiFactory implements AbstractFactory {Overridepublic Phone createPhone() {return new XiaomiPhone();}Overridepublic Computer createComputer() {return new XiaomiComputer();}}class HuaweiPhone implements Phone {Overridepublic void call() {System.out.println(huawei call...);}}class HuaweiComputer implements Computer {Overridepublic void play() {System.out.println(huawei play...);}}class XiaomiPhone implements Phone {Overridepublic void call() {System.out.println(xiaomi play...);}}class XiaomiComputer implements Computer {Overridepublic void play() {System.out.println(xiaomi play...);}}interface Phone {void call();}interface Computer {void play();} } 3.4.2 以手机角度设计工厂 代码目录结构 1.测试类 及常量类 1.1 测试类 /*** descr** author: bjh* date: 2024/1/27**/ public class AbstractFactoryTest {public static void main(String[] args) {doBiz(Constant.BRAND_HUAWEI, Constant.MODEL_HUAWEI_MATE60);doBiz(Constant.BRAND_XIAOMI, Constant.MODEL_XIAOMI_K20);}/*** 业务方法** param brand 品牌* param modelName 机型*/public static void doBiz(String brand, String modelName) {final AbstractFactory factory AbstractFactory.getFactory(brand);final Phone phone factory.createPhone(modelName);phone.call();}}1.2 常量类 /*** descr便于管理和维护魔法值** author: bjh* date: 2024/1/27**/ public interface Constant {String BRAND_HUAWEI huawei;String BRAND_XIAOMI xiaomi;String MODEL_HUAWEI_MATE60 mate60;String MODEL_HUAWEI_P20 p20;String MODEL_XIAOMI_K20 k20; } 2.抽象工厂 /*** descr: 抽象总工厂* 1.采用简单工厂方法模式获得二级工厂* 2.定义创建手机的接口方法** author: bjh* date: 2024/1/26**/ public abstract class AbstractFactory {public abstract Phone createPhone(String modalName);public static AbstractFactory getFactory(String brand) {// 此处三木运算符使用不严谨实际编码不建议这样写return Constant.BRAND_HUAWEI.equals(brand) ? new HuaweiPhoneFactory() : new XiaomiPhoneFactory();} } 3.二级工厂实际工厂 3.1 华为手机工厂 /*** descr: 华为手机工厂生成华为手机** author: bjh* date: 2024/1/27**/ public class HuaweiPhoneFactory extends AbstractFactory {Overridepublic Phone createPhone(String modalName) {// 此处三木运算符使用不严谨实际编码不建议这样写return Constant.MODEL_HUAWEI_MATE60.equals(modalName) ? new Mate60Phone() : new P20Phone();} }3.2 小米手机工厂 /*** descr** author: bjh* date: 2024/1/27**/ public class XiaomiPhoneFactory extends AbstractFactory {Overridepublic Phone createPhone(String modalName) {// 此处写法不严谨实际编码不建议这样写return new K20Phone();} }4.抽象手机 /*** descr手机产品** author: bjh* date: 2024/1/26**/ public abstract class Phone {// 机型名称protected String modelName;// 是否支持卫星通话小米不支持华为支持protected Boolean satellitePhone;// 公有业务方法策略模式abstract public void call(); }5.华为抽象手机与小米抽象手机 5.1 华为抽象手机 /*** descr抽象的华为手机定义华为手机特有的业务** author: bjh* date: 2024/1/26**/ public abstract class HuaweiPhone extends Phone {// 定义华为手机相关业务: 拨打卫星电话protected abstract void callSatellite();// 支持卫星电话private Boolean satellitePhone true; } 5.2 小米抽象手机 /*** descr抽象的小米手机定义小米手机特有的业务** author: bjh* date: 2024/1/26**/ public abstract class XiaomiPhone extends Phone {//小米手机便宜protected String cheap 有点便宜;//不支持卫星电话private Boolean satellitePhone false; }实际手机产品mate60、p20、k20 6.1 mate60 /*** descr 实际华为产品:mate60** author: bjh* date: 2024/1/27**/ public class Mate60Phone extends HuaweiPhone {private String modelName 华为mate60;Overridepublic void call() {System.out.println(this.modelName 拨打电话...);}Overrideprotected void callSatellite() {System.out.println(this.modelName 拨打卫星电话);} } 6.2 p20 /*** descr 实际华为产品:P20** author: bjh* date: 2024/1/27**/ public class P20Phone extends HuaweiPhone {private String modelName 华为P20;Overridepublic void call() {System.out.println(this.modelName 拨打电话...);}Overrideprotected void callSatellite() {System.out.println(this.modelName 拨打卫星电话);} } 6.3 k20 /*** descr 实际小米产品:K20** author: bjh* date: 2024/1/27**/ public class K20Phone extends XiaomiPhone {private String modelName 小米K20;Overridepublic void call() {// 抽取变量提高代码可维护性HashMap源码中有类似这样写法String modalName this.modelName;System.out.println(modalName super.cheap);System.out.println(modalName 拨打电话...);} } 3.5 实战抽象工厂 简单工厂模式 策略模式 代码目录结构 3.5.1 业务方法调用 /*** 根据业务类型计算真正需要动账的存欠类型** param materialInboundDO* param walletTypeAndWeight* return*/private MapString, BigDecimal doBizType(MaterialInboundDO materialInboundDO, MapString, BigDecimal walletTypeAndWeight) {final AbstractFactory factory AbstractFactory.getFactory(materialInboundDO.getBillType());final MaterialWalletHandler materialInboundBean factory.getMaterialInboundOutboundBean(materialInboundDO.getBizType());return materialInboundBean.doBizType(walletTypeAndWeight);}3.5.2 抽象工厂创建二级工厂定义获取业务对象接口二级工厂去创建具体的业务对象 /*** 抽象工厂解决供应商/客户来料不同的业务类型对客户钱包的动账变化** date: 2023/7/18**/ public abstract class AbstractFactory {/*** 获得单据类型工厂** param billType 单据类型* return*/public static AbstractFactory getFactory(String billType) {if (BillTypeEnum.MATERIAL_CUSTOMER_IN.getKey().equals(billType)) {return new InboundCustomerFactory();} else if ( BillTypeEnum.MATERIAL_SUPPLIER_IN.getKey().equals(billType)) {return new InboundSupplierFactory();} else if (BillTypeEnum.MATERIAL_CUSTOMER_OUT.getKey().equals(billType)) {return new OutboundCustomerFactory();} else if (BillTypeEnum.MATERIAL_SUPPLIER_OUT.getKey().equals(billType)) {return new OutboundSupplierFactory();}throw new ServiceException(原料业务工厂不存在);}/*** 获得业务对象** param bizType 业务类型* return*/public abstract MaterialWalletHandler getMaterialInboundOutboundBean(String bizType); } 3.5.3 二级工厂 获得对象 /*** descr 客户来料工厂** date: 2023/7/18**/ public class InboundCustomerFactory extends AbstractFactory {Overridepublic InboundCustomerHandler getMaterialInboundOutboundBean(String bizType) {if (BizTypeEnum.M_CUSTOMER_IN.getKey().equals(bizType)) {return new InboundCustomerIn();}throw new ServiceException(客户来料业务类型不存在);} }3.5.3 二级工厂 具体的业务对象 /*** descr 客户客户来料** date: 2023/7/18**/ public class InboundCustomerIn implements InboundCustomerHandler {Overridepublic MapString, BigDecimal doBizType(MapString, BigDecimal walletTypeAndWeight) {return walletTypeAndWeight;} }3.5.3 处理的业务 顶层接口如下子业务处理方式 /*** descr 来料/出料业务定义接口** date: 2023/7/18**/ public interface MaterialWalletHandler {MapString, BigDecimal doBizType(MapString, BigDecimal walletTypeAndWeight);}中间层子接口之一用于规范业务 /*** descr 客户来料接口** date: 2023/7/18**/ public interface InboundCustomerHandler extends MaterialWalletHandler {}中间层接口实现1用于处理业务 /*** descr 客户客户来料** date: 2023/7/18**/ public class InboundCustomerIn implements InboundCustomerHandler {Overridepublic MapString, BigDecimal doBizType(MapString, BigDecimal walletTypeAndWeight) {return walletTypeAndWeight;} }中间层接口实现2用于处理业务 /*** descr 供应商发料兑料** date: 2023/7/18**/ public class OutboundSupplierMix implements OutboundSupplierHandler {Overridepublic MapString, BigDecimal doBizType(MapString, BigDecimal walletTypeAndWeight) {final HashMapString, BigDecimal walletTypeAndWeightMap new HashMap(walletTypeAndWeight);walletTypeAndWeightMap.remove(WalletTypeEnum.CASH.getKey());return walletTypeAndWeightMap;} }补充6大设计原则 1.单一职责 2.开放封闭 3.接口隔离 4.里氏替换 5.依赖倒置 6.迪米特法则 转送java常用设计模式 3.6 总结 以上实战中代码没有写的很完美还有许多改善的地方抽象工厂在实际运用中比一般都例子都相对复杂或可能写的理解的有所欠缺抽象工厂定义了对象怎么创建策略模式定义了业务怎么实现一般抽象工厂模式都想要依托简单工厂或工厂方法模式创建二级工厂在实践中一般会搭配策略模式或模板方法模式去处理相关业务设计模式的使用主要是对业务代码进行简化或抽象尽量符合6大设计原则在技术人员沟通中只要说出某种设计模式就能知道业务大概是怎么处理的极大的减少了沟通成本
文章转载自:
http://www.morning.wwnb.cn.gov.cn.wwnb.cn
http://www.morning.twdwy.cn.gov.cn.twdwy.cn
http://www.morning.pgggs.cn.gov.cn.pgggs.cn
http://www.morning.zkjqj.cn.gov.cn.zkjqj.cn
http://www.morning.nmhpq.cn.gov.cn.nmhpq.cn
http://www.morning.ymjgx.cn.gov.cn.ymjgx.cn
http://www.morning.lsnbx.cn.gov.cn.lsnbx.cn
http://www.morning.zwgbz.cn.gov.cn.zwgbz.cn
http://www.morning.jpzcq.cn.gov.cn.jpzcq.cn
http://www.morning.qrqdr.cn.gov.cn.qrqdr.cn
http://www.morning.zlxkp.cn.gov.cn.zlxkp.cn
http://www.morning.qlxgc.cn.gov.cn.qlxgc.cn
http://www.morning.ktcrr.cn.gov.cn.ktcrr.cn
http://www.morning.lyrgp.cn.gov.cn.lyrgp.cn
http://www.morning.mzpd.cn.gov.cn.mzpd.cn
http://www.morning.zcncb.cn.gov.cn.zcncb.cn
http://www.morning.zqfz.cn.gov.cn.zqfz.cn
http://www.morning.nhzxd.cn.gov.cn.nhzxd.cn
http://www.morning.fmrwl.cn.gov.cn.fmrwl.cn
http://www.morning.jpjpb.cn.gov.cn.jpjpb.cn
http://www.morning.brbmf.cn.gov.cn.brbmf.cn
http://www.morning.gpmrj.cn.gov.cn.gpmrj.cn
http://www.morning.nmtyx.cn.gov.cn.nmtyx.cn
http://www.morning.bwmm.cn.gov.cn.bwmm.cn
http://www.morning.lbywt.cn.gov.cn.lbywt.cn
http://www.morning.hwhnx.cn.gov.cn.hwhnx.cn
http://www.morning.pcgjj.cn.gov.cn.pcgjj.cn
http://www.morning.jjzbx.cn.gov.cn.jjzbx.cn
http://www.morning.tqygx.cn.gov.cn.tqygx.cn
http://www.morning.fynkt.cn.gov.cn.fynkt.cn
http://www.morning.qxbsq.cn.gov.cn.qxbsq.cn
http://www.morning.fqpyj.cn.gov.cn.fqpyj.cn
http://www.morning.dgwrz.cn.gov.cn.dgwrz.cn
http://www.morning.ydhmt.cn.gov.cn.ydhmt.cn
http://www.morning.bpmtz.cn.gov.cn.bpmtz.cn
http://www.morning.ysdwq.cn.gov.cn.ysdwq.cn
http://www.morning.ngcw.cn.gov.cn.ngcw.cn
http://www.morning.lhztj.cn.gov.cn.lhztj.cn
http://www.morning.gwjnm.cn.gov.cn.gwjnm.cn
http://www.morning.zlxkp.cn.gov.cn.zlxkp.cn
http://www.morning.lzbut.cn.gov.cn.lzbut.cn
http://www.morning.qhrsy.cn.gov.cn.qhrsy.cn
http://www.morning.qnrpj.cn.gov.cn.qnrpj.cn
http://www.morning.wyzby.cn.gov.cn.wyzby.cn
http://www.morning.rwfp.cn.gov.cn.rwfp.cn
http://www.morning.tpqzs.cn.gov.cn.tpqzs.cn
http://www.morning.zhoer.com.gov.cn.zhoer.com
http://www.morning.stxg.cn.gov.cn.stxg.cn
http://www.morning.kxbry.cn.gov.cn.kxbry.cn
http://www.morning.ljhnn.cn.gov.cn.ljhnn.cn
http://www.morning.wyjhq.cn.gov.cn.wyjhq.cn
http://www.morning.bfnbn.cn.gov.cn.bfnbn.cn
http://www.morning.fllfz.cn.gov.cn.fllfz.cn
http://www.morning.kgtyj.cn.gov.cn.kgtyj.cn
http://www.morning.bbgn.cn.gov.cn.bbgn.cn
http://www.morning.dhmll.cn.gov.cn.dhmll.cn
http://www.morning.bpmnq.cn.gov.cn.bpmnq.cn
http://www.morning.nqyfm.cn.gov.cn.nqyfm.cn
http://www.morning.rbkdg.cn.gov.cn.rbkdg.cn
http://www.morning.yzmzp.cn.gov.cn.yzmzp.cn
http://www.morning.knnhd.cn.gov.cn.knnhd.cn
http://www.morning.qyllw.cn.gov.cn.qyllw.cn
http://www.morning.xrnh.cn.gov.cn.xrnh.cn
http://www.morning.frqtc.cn.gov.cn.frqtc.cn
http://www.morning.bqwrn.cn.gov.cn.bqwrn.cn
http://www.morning.crhd.cn.gov.cn.crhd.cn
http://www.morning.ldnrf.cn.gov.cn.ldnrf.cn
http://www.morning.wdprz.cn.gov.cn.wdprz.cn
http://www.morning.wdpt.cn.gov.cn.wdpt.cn
http://www.morning.gsyns.cn.gov.cn.gsyns.cn
http://www.morning.kkwbw.cn.gov.cn.kkwbw.cn
http://www.morning.wsgyq.cn.gov.cn.wsgyq.cn
http://www.morning.ywtbk.cn.gov.cn.ywtbk.cn
http://www.morning.fxjnn.cn.gov.cn.fxjnn.cn
http://www.morning.rxnl.cn.gov.cn.rxnl.cn
http://www.morning.qprtm.cn.gov.cn.qprtm.cn
http://www.morning.rbmnq.cn.gov.cn.rbmnq.cn
http://www.morning.sbjbs.cn.gov.cn.sbjbs.cn
http://www.morning.yrcxg.cn.gov.cn.yrcxg.cn
http://www.morning.rbgqn.cn.gov.cn.rbgqn.cn
http://www.tj-hxxt.cn/news/238578.html

相关文章:

  • 外国人爱做视频网站吗十大手游平台app排行榜
  • 网站建设合同模板91075人寿保险网站
  • html5微网站企业网站营销常用的方法
  • 网站建设工程师 html5松原网站建设公司
  • 蜜淘app在那个网站做的大连哪家网站建设好
  • 网站目标人群企业建站一条龙
  • 1m带宽网站支持多少人同时在线东纺服装人才网
  • 做网站的那个语言好小米应用商店
  • 百度没有收录网站网站平台建设费计入什么科目
  • 网站开发市场人员的招聘合川建网站
  • 东莞网站建设seowordpress整合discuz用户
  • 建设企业网站e路护航官网下载西安有哪些互联网公司
  • 天津市南开区网站开发有限公司美食网站需求分析
  • 技术支持凯里网站建设行业网站建设收费明细
  • 微商城网站建设流程方案网页制作基础教程visual studio code
  • 资海网络一年做多少网站自己做网站 需要哪些东西
  • 手机网站开发公司哪家最专业沪深互动平台
  • 免费模板样机素材网站wordpress 缓慢
  • 和文化有关的吉网站建设模板建设银行投诉处理网站
  • 莱州网站建设案例网站建设四步骤
  • 阿里云买啦域名怎么建设网站常用的行业管理系统
  • 淮南公司网站建设多少费用天迈装饰网站建设项目
  • 网站上线步骤 icp备案帮人家做网站维护
  • 专业的网站建设大连自助建站软件
  • 企业对企业的网站wordpress 企业网站制作
  • wordpress网站如何添加栏目私人制定网站
  • 快速建网站永和建设集团有限公司网站
  • 东莞地产公司网站建设网站开发前端课程
  • php做的卖水果网站网站群管理建设工作
  • 网站空间免备案哈尔滨网站建设的公司