标签:log 表示 相同 href esc img 针对 第二部分 override
1 public interface IBuilder { 2 3 /** 4 * buildPart1 5 * 6 * @description 建造产品的第一部分 7 * @author luokangyuan 8 * @date 2019/10/27 17:15 9 * @version 1.0.0 10 */ 11 void buildPart1(); 12 13 /** 14 * buildPart2 15 * 16 * @description 建造产品的第二部分 17 * @author luokangyuan 18 * @date 2019/10/27 17:15 19 * @version 1.0.0 20 */ 21 void buildPart2(); 22 23 /** 24 * buildPart3 25 * 26 * @description 建造产品的第三部分 27 * @author luokangyuan 28 * @date 2019/10/27 17:15 29 * @version 1.0.0 30 */ 31 void buildPart3(); 32 33 /** 34 * build 35 * 36 * @description 得到产品 37 * @return 产品 38 * @author luokangyuan 39 * @date 2019/10/27 17:16 40 * @version 1.0.0 41 */ 42 Product build();
1 public class TruckConcreateBuilder implements IBuilder{ 2 3 private Product product = new Product(); 4 @Override 5 public void buildPart1() { 6 product.setPart1("货车轮胎完成"); 7 } 8 9 @Override 10 public void buildPart2() { 11 product.setPart2("货车发动机完成"); 12 } 13 14 @Override 15 public void buildPart3() { 16 product.setPart3("货车车架完成"); 17 } 18 19 @Override 20 public Product build() { 21 return product; 22 } 23 } 24 public class ConcreteBuilder implements IBuilder { 25 private Product product = new Product(); 26 27 @Override 28 public void buildPart1() { 29 product.setPart1("轮胎完成"); 30 } 31 32 @Override 33 public void buildPart2() { 34 product.setPart2("发动机完成"); 35 } 36 37 @Override 38 public void buildPart3() { 39 product.setPart3("车架完成"); 40 } 41 42 @Override 43 public Product build() { 44 return product; 45 } 46 }
1 @AllArgsConstructor 2 @Data 3 public class Conductor { 4 5 private IBuilder builder; 6 7 /** 8 * construct 9 * 10 * @description 指挥者负责产品的创建流程 11 * @return 产品 12 * @author luokangyuan 13 * @date 2019/10/27 19:13 14 * @version 1.0.0 15 */ 16 public Product construct() { 17 builder.buildPart1(); 18 builder.buildPart2(); 19 builder.buildPart3(); 20 return builder.build(); 21 } 22 }
1 @Data 2 public class Product { 3 4 /* 组成产品的第一部分*/ 5 private String part1; 6 7 /* 组成产品的第一部分*/ 8 private String part2; 9 10 /* 组成产品的第一部分*/ 11 private String part3; 12 }
1 public static void main(String[] args) { 2 IBuilder builder = new ConcreteBuilder(); 3 Conductor conductor = new Conductor(builder); 4 Product product = conductor.construct(); 5 log.info("产品信息:{},{},{}", product.getPart1(), product.getPart2(),product.getPart3()); 6 conductor.setBuilder(new TruckConcreateBuilder()); 7 Product truck = conductor.construct(); 8 log.info("产品信息:{},{},{}", truck.getPart1(), truck.getPart2(), truck.getPart3()); 9 }
转载于:http://luokangyuan.com/si-ke-she-ji-mo-shi-jian-zao-zhe-mo-shi/
标签:log 表示 相同 href esc img 针对 第二部分 override
原文地址:https://www.cnblogs.com/it-deepinmind/p/13230363.html