为什么要封一类? [英] Why seal a class?

查看:129
本文介绍了为什么要封一类?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想听到的是密封类在.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.

这篇关于为什么要封一类?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆