Constructor with all class properties or default constructor with setters?

前端 未结 9 1952
无人及你
无人及你 2020-12-24 14:03

Following are the two approaches:

  • constructor with all the class properties

Pros: I have to put an exact number of types of parameters so if I m

9条回答
  •  南笙
    南笙 (楼主)
    2020-12-24 14:38

    There are other strategies here, too. Before trying to figure out how to deal with lots of parameters, I think it is important to re-visit your design and look at whether your class is doing too much. See if you can group some of the parameters together into a new class, and move some behavior into that class.

提交回复
热议问题