使用如下写法相对比较简洁,仅供参考
package design.builder;
/**
* @author yi qiang
* @date 2021/4/24 0:55
*/
public class Shop {
private String name;
private String size;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getSize() {
return size;
}
public void setSize(String size) {
this.size = size;
}
@Override
public String toString() {
return "Shop{" +
"name='" + name + '\'' +
", size='" + size + '\'' +
'}';
}
public static Builder builder(){
return new Builder();
}
public static class Builder{
private final Shop shop=new Shop();
public Builder name(String name){
shop.setName(name);
return this;
}
public Builder size(String size){
shop.setSize(size);
return this;
}
public Shop build(){
return shop;
}
}
}