Builder pattern vs. config object

后端 未结 9 439
执笔经年
执笔经年 2021-01-31 08:40

The builder pattern is popular to create immutable objects, but there is some programming overhead to create a builder. So I wonder why not simply using a config object.

9条回答
  •  心在旅途
    2021-01-31 09:19

    The builder pattern improves decoupling - your Product can be an interface and the only class that knows about the implementation (or implementations, in some cases) is the builder. If the builder also implements an interface then you can inject this into your code to increase decoupling further.

    This decoupling means your code is more maintainable and easier to test.

提交回复
热议问题