Skip to content

建造者模式

定义:将一个复杂对象的构建与它的表示分离,使得同样的构建过程可以创建不同的表示。

java
public class Demo {
    public Demo(Bulider bulider) {
    }

    public void showName() {
        System.out.println("name: " + this.name);
    }

    public static class Bulider {
        private String name;

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

        public Demo build() {
            return new Demo(this);
        }
    }
}