關於builder模式的使用

1、Android studio 安裝插件 InnerBuilder

2、ctrl+alt+s ---> generate--->Builder

3、

public class MachineType {
    private String engintType;
    private String controllerType;
    private String yyPupmpType;
    private String yyvalvelType;

    public String getEngintType() {
        return engintType;
    }

    public String getControllerType() {
        return controllerType;
    }

    public String getYyPupmpType() {
        return yyPupmpType;
    }

    public String getYyvalvelType() {
        return yyvalvelType;
    }

    private MachineType(Builder builder) {
        engintType = builder.engintType;
        controllerType = builder.controllerType;
        yyPupmpType = builder.yyPupmpType;
        yyvalvelType = builder.yyvalvelType;
    }


    public static final class Builder {
        private String engintType;
        private String controllerType;
        private String yyPupmpType;
        private String yyvalvelType;

        public Builder() {
        }

        public Builder engintType(String val) {
            engintType = val;
            return this;
        }

        public Builder controllerType(String val) {
            controllerType = val;
            return this;
        }

        public Builder yyPupmpType(String val) {
            yyPupmpType = val;
            return this;
        }

        public Builder yyvalvelType(String val) {
            yyvalvelType = val;
            return this;
        }

        public MachineType build() {
            return new MachineType(this);
        }
    }
}
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章