详细学习笔记链接:
http://www.cnblogs.com/yulinfeng/archive/2017/08/03/7282649.html
1 Builder模式
package com.qunar.bean;
/**
* Created by chenjunwei on 2017/11/6.
*/
public class Student {
private String name;
private int age;
private String sex;
private String grade;
public static class Builder {
private String name;
private int age;
private String sex = "";
protected String grade = "";
public Builder(String name, int age) {
this.name = name;
this.age = age;
}
public Builder sex(String sex) {
this.sex = sex;
return this;
}
public Builder grade(String grade) {
this.grade = grade;
return this;
}
public Student build() {
return new Student(this);
}
}
private Student(Builder builder) {
this.name = builder.name;
this.age = builder.age;
this.sex = builder.sex;
this.grade = builder.grade;
}
}