Java constructor with large arguments or Java bean getter/setter approach

后端 未结 18 2146
清歌不尽
清歌不尽 2020-12-12 21:29

I can\'t decide which approach is better for creating objects with a large number of fields (10+) (all mandatory) the constructor approach of the getter/setter. Constructor

18条回答
  •  天涯浪人
    2020-12-12 22:06

    IMHO, you should pass everything that is needed for an object to be valid according to your business logic in the constructor.

    If the argument list is lengthy, you could create an object that contains the arguments and pass that.

提交回复
热议问题