为什么密封一个班级 [英] Why seal a class

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

问题描述

我想从Bitmap继承添加属性,但我不能因为它是封闭的b $ b。有没有理由去上课?


谢谢,

Michael

I want to inherit from Bitmap to add a property but I can''t because it''s
sealed. Is there any reason to seal a class?

Thanks,
Michael

推荐答案



Michael C schreef:

Michael C schreef:

我想从Bitmap继承添加属性,但我不能因为它'这是

密封。有没有理由去上课?


谢谢,

Michael
I want to inherit from Bitmap to add a property but I can''t because it''s
sealed. Is there any reason to seal a class?

Thanks,
Michael



主要密封类的目的是取消继承

功能,这样用户就无法从该特定类派生一个类。

这样你可以密封边界你的申请。通常

它是用静态类完成的。结构始终是密封的。


在这种情况下,我唯一能想到的是Microsoft

程序员不希望任何派生,因为Bitmap class

实现了Image类中声明的成员。也许那个

覆盖它们可能会导致其他课程出现问题。


我希望这个答案能为您提供所需的所有信息。

The main purpose of a sealed class is to take away the inheritance
feature so the user can not derive a class from that particular class.
In this way you can seal the boundaries of your application. Normally
it is done with static classes. Structs are always sealed.

The only thing i can think of in this case is that the Microsoft
programmers didn''t want any derivation because the Bitmap class
implements the members declared in the Image class. Perhaps that
overriding them could cause problems in other classes.

I hope that this answer gives you all the information that you want.





这是一个设计决定,它表明没有进一步的

继承该课程的预期。

-

-

Ignacio Machin,

ignacio .machin AT dot.state.fl.us

佛罗里达州交通局


" Michael C" < no **** @ nospam.comwrote in message

news:en ************* @ TK2MSFTNGP05.phx.gbl ...
Hi,

It''s a design decision , it''s an indication that there is no further
inheritance expected for that class.
--
--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

"Michael C" <no****@nospam.comwrote in message
news:en*************@TK2MSFTNGP05.phx.gbl...

>我想从Bitmap继承添加属性,但我不能因为它被封存了。有没有理由去上课?


谢谢,

Michael
>I want to inherit from Bitmap to add a property but I can''t because it''s
sealed. Is there any reason to seal a class?

Thanks,
Michael



" Ignacio Machin(.NET / C#MVP)" < ignacio.machin AT dot.state.fl.uswrote
消息新闻中的
:OK ************** @ TK2MSFTNGP05.phx.gbl ...
"Ignacio Machin ( .NET/ C# MVP )" <ignacio.machin AT dot.state.fl.uswrote
in message news:OK**************@TK2MSFTNGP05.phx.gbl...




这是一个设计决定,它表明没有进一步的
该类的预期继承。
Hi,

It''s a design decision , it''s an indication that there is no further
inheritance expected for that class.



很遗憾,我只想添加一些相当无害的属性,比如标签

属性,这样我就可以传递一些额外的信息围绕位图。如果继续使用位图可能会导致问题,如果某些方法被覆盖,那么它会导致问题。如果
被覆盖并不是真的那么重要。我们可以使用api引起各种各样的问题

但是我们仍然会这样:-)


Michael

It''s a pity, I just want to add some fairly harmless properties like a Tag
property so I can pass some extra info around with the bitmap. It seams to
me that if inheriting the bitmap could cause problems if certain method are
overridden isn''t really that big a deal. We can cause all sorts of problems
using the api but we still get to go that :-)

Michael


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

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