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

后端 未结 6 2184
自闭症患者
自闭症患者 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:28

    I see two potential issues:

    • Are the methods you call in initializeCanvas private or final? If they are not, it's possible for a subclass to override them and unwittingly break your constructor.

    • Are you doing graphics operations in the drawBoundaries method? It's good practice for a constructor to do only the minimum necessary to create a valid object. Are those operations necessary for the canvas to have a valid initial state?

提交回复
热议问题