Why seal a class?

前端 未结 10 1924
醉酒成梦
醉酒成梦 2020-11-28 04:51

I\'d like to hear what is the motivation behind the bulk of sealed classes in the .Net framework. What is the benefit of sealing a class? I cannot fathom how not allowing in

10条回答
  •  攒了一身酷
    2020-11-28 05:40

    To determine whether to seal a class, method, or property, you should generally consider the following two points:

    •The potential benefits that deriving classes might gain through the ability to customize your class.

    •The potential that deriving classes could modify your classes in such a way that they would no longer work correctly or as expected.

提交回复
热议问题