| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 4239 人关注过本帖
标题:[讨论]接口,回贴就给分
只看楼主 加入收藏
幻风幻云
Rank: 1
等 级:新手上路
帖 子:762
专家分:0
注 册:2005-1-14
收藏
 问题点数:0 回复次数:71 
[讨论]接口,回贴就给分
一个接口声明一个只有抽象成员的引用类型。跟C++中相似的概念为:一个结构的成员,且方法等于0。如果你不知道那些概念的任何东西,这里就是在C#中一个接口实际所做的。仅仅只存在着方法标志,但根本就没有执行代码。这就暗示了不能实例化一个接口,只能实例化一个派生自该接口的对象。 可以在一个接口中定义方法、属性和索引。所以,对比一个类,接口有什么特殊性呢?当定义一个类时,可以派生自多重接口,而你只能可以从仅有的一个类派生。 你可能会问:"OK,但我必须实现所有的接口成员,那么我能从这个途径得到什么呢?" 我想举一个来自.NET的例子:很多类实现了IDictionary 接口。你可以使用简单的类型转换访问接口: IDictionary myDict = (IDictionary)someobjectthatsupportsit; 现在你的代码可以访问字典了。可等等,我说很多类可以实现这个接口——所以,你可以在多个地方重用代码来访问IDictionary 接口!一旦学会,任何地方都可使用。 当你决定在类设计中使用接口时,学习更多关于面向对象的设计是个好主意。这本书不能教你这些概念,但你可以学习如何创建接口。以下的代码段定义接口IFace,它只有一个方法: interface IFace { void ShowMyFace(); } 正如我所提到的,不能从这个定义实例化一个对象,但可以从它派生一个类。因此,该类必须实现ShowMyFace抽象方法: class CFace:IFace { public void ShowMyFace() { Console.WriteLine("implementation"); } } 接口成员和类成员的区别在于,接口成员不能被实现。因此,我不想在下一章中再次提到这一点。 关于上面一段话,有什么独特的理解,或者有问题,或者回答问题者,都可获得送分,灌水得1分。
搜索更多相关主题的帖子: 接口 
2005-04-08 14:39
yushengou
Rank: 1
等 级:新手上路
帖 子:401
专家分:0
注 册:2005-3-30
收藏
得分:0 
“接口是一种内置的机制,可以通过它们很容易地定义任意数量的行为,然后让任意数量的类以任意组合实现这些行为,而根本不必考虑类层次结构。”
这句话怎么样啊

我是初学者,希望大家能多多帮助我 /bbs/showimg.asp?BoardID=34&filename=2005-4/200542294030151.gif" border="0" onload="if(this.width>screen.width*0.7) {this.resized=true; this.width=screen.width*0.7; this.alt='Click here to open new window\nCTRL+Mouse wheel to zoom in/out';}" onmouseover="if(this.width>screen.width*0.7) {this.resized=true; this.width=screen.width*0.7; this.style.cursor='hand'; this.alt='Click here to open new window\nCTRL+Mouse wheel to zoom in/out';}" onclick="if(!this.resized) {return true;} else {window.open('http://bbs./bbs/showimg.asp?BoardID=34&filename=2005-4/200542294030151.gif');}" onmousewheel="return imgzoom(this);" alt="" />
2005-04-08 14:49
yushengou
Rank: 1
等 级:新手上路
帖 子:401
专家分:0
注 册:2005-3-30
收藏
得分:0 
现在天在看接口呢。理解不了。

我是初学者,希望大家能多多帮助我 /bbs/showimg.asp?BoardID=34&filename=2005-4/200542294030151.gif" border="0" onload="if(this.width>screen.width*0.7) {this.resized=true; this.width=screen.width*0.7; this.alt='Click here to open new window\nCTRL+Mouse wheel to zoom in/out';}" onmouseover="if(this.width>screen.width*0.7) {this.resized=true; this.width=screen.width*0.7; this.style.cursor='hand'; this.alt='Click here to open new window\nCTRL+Mouse wheel to zoom in/out';}" onclick="if(!this.resized) {return true;} else {window.open('http://bbs./bbs/showimg.asp?BoardID=34&filename=2005-4/200542294030151.gif');}" onmousewheel="return imgzoom(this);" alt="" />
2005-04-08 14:54
幻风幻云
Rank: 1
等 级:新手上路
帖 子:762
专家分:0
注 册:2005-1-14
收藏
得分:0 
没有你自己的理解 就当灌水啦

2005-04-08 14:55
yushengou
Rank: 1
等 级:新手上路
帖 子:401
专家分:0
注 册:2005-3-30
收藏
得分:0 
以下是引用幻风幻云在2005-4-8 14:55:59的发言: 没有你自己的理解 就当灌水啦
我咬你啦。第一句这么经典,没看出来吗。 起码要多一点啊

我是初学者,希望大家能多多帮助我 /bbs/showimg.asp?BoardID=34&filename=2005-4/200542294030151.gif" border="0" onload="if(this.width>screen.width*0.7) {this.resized=true; this.width=screen.width*0.7; this.alt='Click here to open new window\nCTRL+Mouse wheel to zoom in/out';}" onmouseover="if(this.width>screen.width*0.7) {this.resized=true; this.width=screen.width*0.7; this.style.cursor='hand'; this.alt='Click here to open new window\nCTRL+Mouse wheel to zoom in/out';}" onclick="if(!this.resized) {return true;} else {window.open('http://bbs./bbs/showimg.asp?BoardID=34&filename=2005-4/200542294030151.gif');}" onmousewheel="return imgzoom(this);" alt="" />
2005-04-08 15:00
幻风幻云
Rank: 1
等 级:新手上路
帖 子:762
专家分:0
注 册:2005-1-14
收藏
得分:0 
你只是简单的复制了一句啊
你说说
你那句和我上面那一段话中那句有什么联系
我就给你++++分

2005-04-08 15:04
yushengou
Rank: 1
等 级:新手上路
帖 子:401
专家分:0
注 册:2005-3-30
收藏
得分:0 
接口怎么在应用中用起来呢。 没有突破口,没有概念。不知道怎么用。 用了这个接口有什么好处啊 ps:总算动脑筋 提问啦

[此贴子已经被幻风幻云于2005-4-8 15:07:25编辑过]


我是初学者,希望大家能多多帮助我 /bbs/showimg.asp?BoardID=34&filename=2005-4/200542294030151.gif" border="0" onload="if(this.width>screen.width*0.7) {this.resized=true; this.width=screen.width*0.7; this.alt='Click here to open new window\nCTRL+Mouse wheel to zoom in/out';}" onmouseover="if(this.width>screen.width*0.7) {this.resized=true; this.width=screen.width*0.7; this.style.cursor='hand'; this.alt='Click here to open new window\nCTRL+Mouse wheel to zoom in/out';}" onclick="if(!this.resized) {return true;} else {window.open('http://bbs./bbs/showimg.asp?BoardID=34&filename=2005-4/200542294030151.gif');}" onmousewheel="return imgzoom(this);" alt="" />
2005-04-08 15:05
yushengou
Rank: 1
等 级:新手上路
帖 子:401
专家分:0
注 册:2005-3-30
收藏
得分:0 
以下是引用幻风幻云在2005-4-8 15:04:41的发言: 你只是简单的复制了一句啊 你说说 你那句和我上面那一段话中那句有什么联系 我就给你++++分
错不是复制的。是我手打的。 是你上面的补充来着。

我是初学者,希望大家能多多帮助我 /bbs/showimg.asp?BoardID=34&filename=2005-4/200542294030151.gif" border="0" onload="if(this.width>screen.width*0.7) {this.resized=true; this.width=screen.width*0.7; this.alt='Click here to open new window\nCTRL+Mouse wheel to zoom in/out';}" onmouseover="if(this.width>screen.width*0.7) {this.resized=true; this.width=screen.width*0.7; this.style.cursor='hand'; this.alt='Click here to open new window\nCTRL+Mouse wheel to zoom in/out';}" onclick="if(!this.resized) {return true;} else {window.open('http://bbs./bbs/showimg.asp?BoardID=34&filename=2005-4/200542294030151.gif');}" onmousewheel="return imgzoom(this);" alt="" />
2005-04-08 15:08
yushengou
Rank: 1
等 级:新手上路
帖 子:401
专家分:0
注 册:2005-3-30
收藏
得分:0 
幻幻你能不能把你的理解用口头表达出来。
书面的看得太多了,很难理解。

我是初学者,希望大家能多多帮助我 /bbs/showimg.asp?BoardID=34&filename=2005-4/200542294030151.gif" border="0" onload="if(this.width>screen.width*0.7) {this.resized=true; this.width=screen.width*0.7; this.alt='Click here to open new window\nCTRL+Mouse wheel to zoom in/out';}" onmouseover="if(this.width>screen.width*0.7) {this.resized=true; this.width=screen.width*0.7; this.style.cursor='hand'; this.alt='Click here to open new window\nCTRL+Mouse wheel to zoom in/out';}" onclick="if(!this.resized) {return true;} else {window.open('http://bbs./bbs/showimg.asp?BoardID=34&filename=2005-4/200542294030151.gif');}" onmousewheel="return imgzoom(this);" alt="" />
2005-04-08 15:12
幻风幻云
Rank: 1
等 级:新手上路
帖 子:762
专家分:0
注 册:2005-1-14
收藏
得分:0 
以下是引用yushengou在2005-4-8 14:49:49的发言: “接口是一种内置的机制,可以通过它们很容易地定义任意数量的行为,然后让任意数量的类以任意组合实现这些行为,而根本不必考虑类层次结构。” 这句话怎么样啊
这句话的意思是不是 一个接口可以派生好多类,这些类之间可以通过这个接口进行访问。与类的内部构造等无关?

2005-04-08 15:15
快速回复:[讨论]接口,回贴就给分
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.021355 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved