[Project combat] Builder creation of design mode, construction mode, translators in different languages

1. Definition:

The internal appearance of the product is separated from the production process of the product, so that a construction process can generate product objects with different internal appearances. The construction mode enables the internal appearance of the product to change independently, and the customer does not need to know the details of the internal composition of the product.

Build patterns enforce a step-by-step build process.

2. Specific cases:

What MM loves to hear most is the sentence "I love you". When you meet MMs in different places, you must be able to say this sentence to her in their dialect. I have a multilingual translator, and each language on the above There is a button. When I see a MM, I just need to press the corresponding button, and it can say "I love you" in the corresponding language. Foreign MMs can also be easily fixed. This is my "I love you" You" builder. (This must be better than the translation machine used by the US military in Iraq)

public interface Builder {
    
       
          // 创建部件A比如创建汽车车轮
  void buildPartA();
  //创建部件 B 比如创建汽车方向盘
  void buildPartB();
  //创建部件 C 比如创建汽车发动机
  void buildPartC(); 
  //返回最后组装成品结果 (返回最后装配好的汽车)
  //成品的组装过程不在这里进行 ,而是转移到下面的Director类别中进行。
  //从而实现了解耦过程和部件
  Product getResult();
}
public class Director {
    
       
       private Builder builder;
   public Director( Builder builder ) {
    
    
     this.builder = builder;
  }
  // 将部件 partA partB partC最后组成复杂对象
  //这里是将车轮 方向盘和发动机组装成汽车的过程
  public void construct() {
    
    
     builder.buildPartA();
     builder.buildPartB();
     builder.buildPartC();   
       }
}

Guess you like

Origin blog.csdn.net/wstever/article/details/129889876