Builder Design Mode

Source: Internet
Author: User

650) This. width = 650; "src =" http://s3.51cto.com/wyfs02/M01/3F/EB/wKioL1PMzQKxSTJRAAKUiSwCEcE781.jpg "Title =" qq 40721081402.jpg "alt =" wkiol1pmzqkxstjraakuiswcece781.jpg "/>

Builder design mode: in my opinion, the core lies in two classes. Builder class and director class. Abstract everythingParts and assembly. The final product is presented to the customer through the cooperation of the two parts ., Only one product is assembled.

When the company grows bigger, it can not only provide one product. Based on the number of existing features and streamlining, you can quickly produce a variety of products, as long as different construct and product. Construct provides three features, indicating that this is a Lenovo thinkpadt430 laptop. If construct only provides a show function, it may be Lenovo's tablet.

public interface Builder {     void call();     void show();     void work();   Product getResult();}
public class Lenovo implements Builder {   private Product lenovo;      public void call() {      // TODO: implement       lenovo.setCallFun("lenovo call");   }      public void show() {      // TODO: implement       lenovo.setShowFun("lenovo show");   }      public void work() {      // TODO: implement       lenovo.setWorkFun("lenovo work");   }      public Product getResult() {      // TODO: implement      return this.lenovo;   }      public Lenovo() {      // TODO: implement      lenovo = new Product();   }}
public class Product {     private String callFun;   private String showFun;     private String workFun;      public String getCallFun() {      return callFun;   }        public void setCallFun(String newCallFun) {      callFun = newCallFun;   }      public String getShowFun() {      return showFun;   }      public void setShowFun(String newShowFun) {      showFun = newShowFun;   }      public String getWorkFun() {      return workFun;   }      public void setWorkFun(String newWorkFun) {      workFun = newWorkFun;   }}
public class Director {   private Builder builder;      public Director(Builder builder) {      // TODO: implement      this.builder= builder;   }      public void construct() {      // TODO: implement      builder.call();      builder.show();      builder.work();   }}
public class CallBuilder {private static Builder builder;private static Director director;private static Product product;public static void main(String[] args) {builder = new Lenovo();director = new Director(builder);director.construct();product = builder.getResult();System.out.println(product.getCallFun());System.out.println(product.getShowFun());System.out.println(product.getWorkFun());}}


Builder Design Mode

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.