为什么要封一类?

为什么要封一类?

问题描述:

我想听到的是密封类在.NET Framework中的大部分背后的动机。什么是密封类的好处?我无法捉摸如何不让继承可以是有益的,最有可能不是唯一一个争取这些类。

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 inheritance can be useful and most likely not the only one fighting these classes.

那么,为什么是框架设计这种方式并不会是unbreaking改变开封的一切吗?必须有另一种原因,但只是被恶?

So, why is the framework designed this way and wouldn't it be unbreaking change to unseal everything? There must be another reason but just being evil?

  • 有时班太precious并没有设计被继承。
  • 在运行时/反射可以继承的假设密封类寻找类型时。这方面的一个很好的例子是 - 属性建议被密封的查询运行速度。 type.GetCustomAttributes(typeof运算(MyAttribute))将执行,如果MyAttribute是密封的显著更快。

有关这一主题的MSDN文章是由密封类限制扩展

The MSDN article for this topic is Limiting Extensibility by Sealing Classes.