Is it violation of Clean Code to call init method in constructor like this

后端 未结 6 2182
自闭症患者
自闭症患者 2020-12-14 21:05

My concern in the code below is that the param to constructor is not actually directly mapped to the class\'s instance fields. The instance fields derive value from the para

6条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-12-14 21:30

    A private init function might be useful if you have multiple constructors where some parameters are defaulted or inferred. After everything is determined, one private init function fills in the object.

    In a one-constructor class, probably not.

提交回复
热议问题