How to improve the builder pattern?

后端 未结 10 909
野性不改
野性不改 2020-12-02 10:34

Motivation

Recently I searched for a way to initialize a complex object without passing a lot of parameter to the constructor. I tried it with the builder pattern,

10条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-02 11:30

    I've seen/used this:

    new ComplexBuilder(requiredvarA, requiedVarB).optional(foo).optional(bar).build();
    

    Then pass these to your object that requires them.

提交回复
热议问题