public class PersonBuilder {
/**
* 头像
*/
private String personPhoto;
/**
* 名字
*/
public String persenName;
/**
* 年龄
*/
private String personAge;
/**
* 密码
*/
private String personPsw;
/**
* 性别
*/
private String personGender;
public PersonBuilder(Builder builder) {
this.personPhoto = builder.personPhoto;
this.persenName = builder.persenName;
this.personAge = builder.personAge;
this.personPsw = builder.personPsw;
this.personGender = builder.personGender;
}
public static class Builder {
/**
* 头像
*/
private String personPhoto;
/**
* 名字
*/
public String persenName;
/**
* 年龄
*/
private String personAge;
/**
* 密码
*/
private String personPsw;
/**
* 性别
*/
private String personGender;
public Builder setPersonPhoto(String personPhoto) {
this.personPhoto = personPhoto;
return this;
}
public Builder setPersenName(String persenName) {
this.persenName = persenName;
return this;
}
public Builder setPersonAge(String personAge) {
this.personAge = personAge;
return this;
}
public Builder setPersonPsw(String personPsw) {
this.personPsw = personPsw;
return this;
}
public Builder setPersonGender(String personGender) {
this.personGender = personGender;
return this;
}
public PersonBuilder build(){
return new PersonBuilder(this);
}
}
@Override
public String toString() {
return "PersonBuilder{" +
"personPhoto='" + personPhoto + '\'' +
", persenName='" + persenName + '\'' +
", personAge='" + personAge + '\'' +
", personPsw='" + personPsw + '\'' +
", personGender='" + personGender + '\'' +
'}';
}
}
Java 设计模式之建造者模式
最新推荐文章于 2022-12-02 16:55:25 发布