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

泰州网站设计贾汪区住房和城乡建设局网站

泰州网站设计,贾汪区住房和城乡建设局网站,阿里云服务器学生,wordpress 强制ssl一、什么是建造者模式#xff1f; 将复杂对象的构建与表示进行分离#xff0c;使得统一的构建过程#xff0c;可以创建出不同的对象表现模式 就是将复杂对象里面的成员变量#xff0c;设置不同的值#xff0c;使得生成出来的对象拥有不同的属性值#xff1b; 二、特点…一、什么是建造者模式 将复杂对象的构建与表示进行分离使得统一的构建过程可以创建出不同的对象表现模式 就是将复杂对象里面的成员变量设置不同的值使得生成出来的对象拥有不同的属性值 二、特点 要解决的问题复杂对象使用不同的构建过程产生拥有不同对象属性的对象调用者只需要设定不同的属性值不需要了解属性值之间是怎么构建出来对象的 抽象建造者抽象创建者接口 实际建造者抽象创建者的不同实现 产品复杂产品 指挥者用来与调用者交互实现通过抽象创建者生产出产品的流程 三、角色和实现 实现方式一 抽象建造者 public interface CarBuilderInterface {Object builderWheel();Object builderFrame();Object builderCoreComponent();} 具体建造者 public class CarBuilderInterfaceImpl implements CarBuilderInterface {Overridepublic Object builderWheel() {System.out.println(生产了一个轮子);return 返回轮子;}Overridepublic Object builderFrame() {System.out.println(生产了一个车架);return 返回车架;}Overridepublic Object builderCoreComponent() {System.out.println(生产了核心组件);return 返回核心组件;} } 具体的产品 public class CarProduct {private String wheel;private String frame;private String coreComponent;public String getWheel() {return wheel;}public void setWheel(String wheel) {this.wheel wheel;}public String getFrame() {return frame;}public void setFrame(String frame) {this.frame frame;}public String getCoreComponent() {return coreComponent;}public void setCoreComponent(String coreComponent) {this.coreComponent coreComponent;} } 指挥者Director实例化建造者通过建造者组织具体的产品 public class CarBuilderDirector {private CarBuilderInterface carBuilderInterface;public CarBuilderDirector(CarBuilderInterface carBuilderInterface) {this.carBuilderInterface carBuilderInterface;}public CarProduct builderCarProduct() {CarProduct carProduct new CarProduct();carProduct.setWheel(carBuilderInterface.builderWheel().toString());carProduct.setFrame(carBuilderInterface.builderFrame().toString());carProduct.setCoreComponent(carBuilderInterface.builderCoreComponent().toString());return carProduct;} } 当需要使用建造者模式进行对象构建时 public class Client {public static void main(String[] args) {CarBuilderInterface carBuilderInterface new CarBuilderInterfaceImpl();CarBuilderDirector carBuilderDirector new CarBuilderDirector(carBuilderInterface);CarProduct carProduct carBuilderDirector.builderCarProduct();System.out.println(生成了一个车 carProduct.getWheel() , carProduct.getFrame() , carProduct.getCoreComponent());} }实现方式二使用静态内部类的方式实现 /*** 通过内部类的形式实现建造者模式并且可以实现链式调用*/ public class CarBuilderExample {private String wheel;private String frame;private String coreComponent;private CarBuilderExample(String wheel, String frame, String coreComponent) {this.wheel wheel;this.frame frame;this.coreComponent coreComponent;}public static class CarBuilderExampleBuilder {private String wheel;private String frame;private String coreComponent;public static CarBuilderExampleBuilder builder() {return new CarBuilderExampleBuilder();}public CarBuilderExampleBuilder wheel(String wheel) {this.wheel wheel;return this;}public CarBuilderExampleBuilder frame(String frame) {this.frame frame;return this;}public CarBuilderExampleBuilder coreComponent(String coreComponent) {this.coreComponent coreComponent;return this;}public CarBuilderExample builderExample() {return new CarBuilderExample(wheel, frame, coreComponent);}}public static void main(String[] args) {CarBuilderExampleBuilder builder CarBuilderExampleBuilder.builder();CarBuilderExample carBuilderExample builder.wheel(轮子).frame(车架).coreComponent(核心部件).builderExample();System.out.println(carBuilderExample.coreComponent carBuilderExample.frame carBuilderExample.wheel);}}lombok包里面的Builder也是通过这种模式实现的 四、与工厂方法和抽象工厂之间的区别 工厂是指创建一个类型的多种实现 抽象工厂是指创建一系列类型的多种实现
http://www.w-s-a.com/news/265496/

相关文章:

  • 做网站需要简介中山网站设计公司
  • 网站怎么做导航栏微信公众号官网登录
  • 1_ 掌握网站开发的基本流程 要求:熟悉网站开发与设计的基本流程.电子商城网站开发
  • 百度网站怎么建设河北省工程造价信息网官网
  • 阿里云网站模板网页设计的合适尺寸是多少
  • 做小程序和做网站哪个好让别人做网站推广需要多少钱
  • 做外贸的几个网站查询网域名解析
  • 酒泉如何做百度的网站seo研究中心好客站
  • 网站设计建设平台户县做网站
  • 一元云购网站开发wordpress博客空间
  • 深圳高端网站建设公司排名如何搭建局域网服务器
  • 照片管理网站模板高端网站开发哪家好
  • 黄冈网站制作wordpress为什么不能显示域名
  • 做网站设计怎么进企业电子商务网站建设与管理教材
  • 设计广告公司网站建设网站开发技术选择
  • 个人网站教程个人网站有必要备案吗
  • 网站建设推广好做吗黄浦企业网站制作
  • 怎样做28网站代理中山网站建设方案外包
  • vs2010做网站前台搭建小网站
  • 做视频必须知道的一些网站wordpress 标签鼠标滑过_弹出的title 代码美化
  • 怎么做室内设计公司网站电商运营培训视频课程
  • 昆明网站策划天津市建筑信息平台
  • 三亚放心游app官方网站wordpress 个人主题
  • 做简单的网站备案平台新增网站
  • 中国建设网站银行网络营销推广方案整合
  • 网站域名列表dede网站白屏
  • 站长工具一区品牌建设卓有成效
  • 电子商务网站建设案例wordpress批量编辑
  • 想代理个网站建设平台100个最佳市场营销案例
  • 钟表东莞网站建设石家庄做网站时光