How many constructors should a class have?

前端 未结 16 1917
一向
一向 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 13:02

    The awnser is: NONE

    Look at the Language Dylan. Its has a other System.

    Instat of a constructors you add more values to your slots (members) then in other language. You can add a "init-keyword". Then if you make a instance you can set the slot to the value you want.

    Ofcourse you can set 'required-init-keyword:' and there are more options you can use.

    It works and it is easy. I dont miss the old system. Writing constructors (and destructors).

    (btw. its still a very fast language)


提交回复
热议问题