接口有什么作用?

编程入门 行业动态 更新时间:2024-10-26 19:37:05
本文介绍了接口有什么作用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

大家好, 我正在使用一本不解释接口的书. 我想知道界面真正的作用,并且我也在使用MEF. 请把我链接到一个好的网站,或者给我一个好的答案. 它还告诉我创建一个接口,但没有告诉我在该接口中创建任何代码.是否有应默认输入的内容或其他内容. 请让我知道. 谢谢.

Hi guys, I am using a book which does not explain about interfaces . I want to know what a interface really does and I am also using MEF. Please link me to a good site or give me a good answer. It also tells me to make an interface but doesn''t tell me to create any code in that interface.Is there something that i should type by default or something . Please let me know. Thank you.

推荐答案

您是否读过MSDN所说的内容?这是很有解释性的. msdn.microsoft/en-us/library/ms173156 (v = vs.110).aspx [ ^ ] Did you read what MSDN says about it? It is quite explanatory. msdn.microsoft/en-us/library/ms173156(v=vs.110).aspx[^]

接口本身不执行任何操作.您可以将接口视为合同,该合同描述了类型要想履行该合同时必须声明的签名方法.然后,您可以使用该类型的实例,以确保它可以完全履行合同,并且使用该实例的代码甚至不必知道该具体类型(请参阅:针对接口进行编程,而不是具体的实现). > 一个空的接口甚至可以用作某种标记,尽管我认为在大多数情况下,属性会更好.没有规定任何方法或属性的接口可以从其继承中添加到任何类型定义中.在您的代码中,您可以检查一种类型是否实现了所说的(空)接口,如果该类型可以实现该情况,则可以做一些事情. 最好的问候, 曼弗雷德(Manfred) An Interface does not do anything on it''s own. You can consider an Interface to be a contract which describes what method(s) with which signature(s) a type has to declare if it wants to fullfill that contract. You can then use an instance of that type in the sure knowledge that it fullfills the contract and the code using that instance does not even have to be aware of that concrete type (See: Programming against interfaces instead of concrete implementations). An empty Interface can even be used as some kind of marker, even though I think Attributes are better for that most of the time. An interface that does not prescribe any method or property can be added to any type definition as inheriting from it. In your code you can check if a type implements said (empty) interface and if the type does you can do something fitting that situation. Best Regards, Manfred

通过以下论坛及其回应.它说明Why we need an Interface www.dotnetspider/forum/13184-OOPS- Why-we-need-an-Interface.aspx [ ^ ] Hi, Go through following forum and its responses. It explains Why we need an Interface www.dotnetspider/forum/13184-OOPS-Why-we-need-an-Interface.aspx[^]

更多推荐

接口有什么作用?

本文发布于:2023-10-07 17:21:01,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1470011.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:有什么   接口   作用

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!