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

很简单的做设计的网站学院网站群建设的目标

很简单的做设计的网站,学院网站群建设的目标,成品网站包含后台么,电商网站建设与维护试题文章目录 一、工厂模式#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.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手机手机小米手机红米手机 两层关系 产品品牌手机华为手机手机小米手机 3.3 模型图解 角色手机总工厂、小米手机工厂、华为手机工厂、手机、小米手机、华为手机、红米手机、华为Mate60手机、华为P60手机 3.4 伪代码 public class AbstractFactory{}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.pierceye.com/news/807400/

相关文章:

  • 网站报备查询android安卓软件下载
  • 百度站长平台网站验证wordpress关闭略缩图
  • 网站怎么做qq微信登陆界面设计的有趣的网站推荐
  • 设计logo网站赚钱注册域名怎么做网站
  • 网站备案 教程网站设计大全推荐
  • 临沂建设局网站官网文明网站建设工作进度表
  • 网站编辑seo旅游网站建设代码
  • 为什么自己做的网站打开是乱码wordpress live-2d
  • 素材下载网站电商自建站
  • 浙江省的网站建设公司有哪些代理注册公司一般多少钱
  • 如何在建设银行网站预约纪念币东莞网站建设服务有什
  • 有哪些可以做h5的网站代理网址上境外网
  • 做网站所需要的代码6红杏直播
  • 南通制作网站wordpress移动版设置
  • 哪个网站有免费ppt下载建筑类网站的推荐理由
  • 视觉差的网站公司外包
  • 基础做网站内蒙住房和城乡建设部网站
  • 发帖效果好的网站展馆展示设计公司排名
  • 童装网站建设文案什么网站做的号
  • 能打开的a站莆田网站建设建站系统
  • 上海市城乡建设管理局网站一个月做网站
  • 网站后台管理系统 aspwordpress拖拽上传
  • 华为手机官方网站登录爬虫做视频网站
  • 山东省工程建设信息官方网站河南网站seo推广
  • 低成本做网站 白之家重庆市建设执业资格注册管理中心网站
  • 电子商务网站建设需求在别的公司做的网站可以转走吗
  • 网站流量怎么做乡1万做网站需要几个人
  • 阿里云centos7做网站怀化网站seo
  • 我做的网站怎样被百度收录易语言 做网站mysql
  • 花店网站模板免费下载9个做简历的网站