Should I recommend sealing classes by default?

后端 未结 13 1249
青春惊慌失措
青春惊慌失措 2021-01-30 01:57

In a big project I work for, I am considering recommending other programmers to always seal their classes if they haven\'t considered how their classes should be subclassed. Oft

13条回答
  •  甜味超标
    2021-01-30 02:57

    I'd like to think that I'm a reasonably-experienced programmer and, if I've learned nothing else, it's that I am remarkably bad at predicting the future.

    Typing sealed is not hard, I just don't want to irritate a developer down the road (who could be me!) who discovers that a problem could be easily solved with a little inheritance.

    I also have no idea how sealing a class makes it more readable. Are you trying to force people to prefer composition to inheritance?

提交回复
热议问题