How many constructors should a class have?

前端 未结 16 1926
一向
一向 2021-02-04 12:34

I\'m currently modifying a class that has 9 different constructors. Now overall I believe this class is very poorly designed... so I\'m wondering if it is poor design for a clas

16条回答
  •  夕颜
    夕颜 (楼主)
    2021-02-04 12:37

    Surely a class should have as many constructors as are required by the class... this doesnt mean than bad design can take over.

    Class design should be that a constructor creates a valid object after is has finished. If you can do that with 1 param or 10 params then so be it!

提交回复
热议问题