建造者模式
可以用在flink中,进行属性拉宽,HadoopRpc就是采用的建造者模式进行构建
public class BuildorTost {
public static void main(String[] args) {
Product build = new Product.Builder()
.setName("xxx")
.setCompany("xxx")
.build();
}
}
class Product {
private String name;
private String company;
public Product() {}
public Product(String name, String company) {
this.name = name;
this.company = company;
}
static class Builder {
private String name;
private String company;
public Builder setName(String name) {
this.name = name;
return this;
}
public Builder setCompany(String company) {
this.company = company;
return this;
}
public Product build() {
return new Product(name, company);
}
}
}