JavaWorld on OO: Getters/Setters vs Builder

后端 未结 4 1518
萌比男神i
萌比男神i 2020-12-28 19:31

Background:

I found this article on JavaWorld, where Allen Holub explains an alternative to Getters/Setters that maintains the principle that the implementation of

4条回答
  •  渐次进展
    2020-12-28 20:04

    When you require a constructor (consider factories in a similar way) for an object, you force the code using your object to pass the essential requirements to the constructor. The more explicit the better. You can leave the optional fields to be set later (injected) using a setter.

提交回复
热议问题