大橙子网站建设,新征程启航
为企业提供网站建设、域名注册、服务器等服务
定义:将一个复杂对象的构建与它的表示分离,使得同样的构建过程可以创建不同的表示。
泗水ssl适用于网站、小程序/APP、API接口等需要进行数据传输应用场景,ssl证书未来市场广阔!成为创新互联建站的ssl证书销售渠道,可以享受市场价格4-6折优惠!如果有意向欢迎电话联系或者加微信:13518219792(备注:SSL证书合作)期待与您的合作!类型:创建类模式
类图:
四个要素
代码实现
class Product { private String name; private String type; public void showProduct(){ System.out.println("名称:"+name); System.out.println("型号:"+type); } public void setName(String name) { this.name = name; } public void setType(String type) { this.type = type; } } abstract class Builder { public abstract void setPart(String arg1, String arg2); public abstract Product getProduct(); } class ConcreteBuilder extends Builder { private Product product = new Product(); public Product getProduct() { return product; } public void setPart(String arg1, String arg2) { product.setName(arg1); product.setType(arg2); } } public class Director { private Builder builder = new ConcreteBuilder(); public Product getAProduct(){ builder.setPart("宝马汽车","X7"); return builder.getProduct(); } public Product getBProduct(){ builder.setPart("奥迪汽车","Q5"); return builder.getProduct(); } } public class Client { public static void main(String[] args){ Director director = new Director(); Product product1 = director.getAProduct(); product1.showProduct(); Product product2 = director.getBProduct(); product2.showProduct(); } }