构造器模式

public class BeanBuilder {
    private int id;
    private String name;
    private String tel;

    private BeanBuilder(int id, String name, String tel) {
        this.id = id;
        this.name = name;
        this.tel = tel;
    }

    public int getId() {
        return id;
    }

    public String getName() {
        return name;
    }

    public String getTel() {
        return tel;
    }

    public static class Builder {

        private int id = 0;
        private String name = null;
        private String tel = null;

        public Builder setId(int id) {
            this.id = id;
            return this;
        }

        public Builder setName(String name) {
            this.name = name;
            return this;
        }

        public Builder setTel(String tel) {
            this.tel = tel;
            return this;
        }

        public BeanBuilder build() {
            //check params
         

            return new BeanBuilder(id, name, tel);
        }
    }

}

你可能感兴趣的:(构造器模式)