Should I recommend sealing classes by default?

后端 未结 13 1012
青春惊慌失措
青春惊慌失措 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

    This is a very opinionated question that's likely to garner some very opinionated answers ;-)

    That said, in my opinion, I strongly prefer NOT making my classes sealed/final, particularly at the beginning. Doing this makes it very difficult to infer the intended extensibility points, and it's nearly impossible to get them right at the beginning. IMHO, overuse of encapsulation is worse than overuse of polymorphism.

提交回复
热议问题