How many constructor arguments is too many?

前端 未结 15 1259
[愿得一人]
[愿得一人] 2020-11-29 15:03

Let\'s say you have a class called Customer, which contains the following fields:

  • UserName
  • Email
  • First Name
  • Last Name

15条回答
  •  暗喜
    暗喜 (楼主)
    2020-11-29 15:41

    If you have unpalatably many arguments, then just package them together into structs / POD classes, preferably declared as inner classes of the class you are constructing. That way you can still require the fields while making the code that calls the constructor reasonably readable.

提交回复
热议问题