什么是接口的使用? [英] What Is The Use Of Interface ?

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

问题描述

Hi,
    I have the below code in my interface. I don't know the exact use of  <T> used in interface. And also please explain each terms in the code.

public interface IInterface: IDisposable
{
IEnumerable<T> GetList(Object Object);
T GetItem(Object Object);
Int32 Save(Object Object);
}


Thanks

推荐答案

1.来自界面的第一个方法返回一个名为T的泛型类型列表,因此T可以替换为任何类型(某些类,其他接口,数字类型,字符串等)。



2.所有方法都有对象的对象作为参数表示可以是任何类型的任何对象。



3.第二种方法从给定参数中获取项目,返回值是泛型类型T(见第1点);



4.最后一种方法似乎保存给定的数据并返回一个整数,这可能是一个错误代码。



5.此接口的使用可能是为更多类应该/可以实现的层或模块或类之间的通信提供一般行为,并且它似乎必须通过提供对泛型类型T的对象列表的访问的类来实现。
1.First method from you interface returns a list of generic type named "T", so "T" can be replaced with any type (some of your classes, other interface, a numeric type, string, etc).

2.All methods have as parameter an object of type Object that mean that can be any object of any type.

3.Second method get a item from the given parameter and the returned value is a generic type T (see 1st point);

4.The last method it seems that save the data given and return an integer, that could be an error code.

5.The use of this interface could be to provide a general behavior for communication between layers or modules or classes that should/could be implemented by more classes, and it seems that must be implemented by classes that provide access to a list of objects of generic type "T".


这是两个不相关的主题:泛型和接口。这两件事都与基本面有关,需要大量时间才能正确解释。只需分别学习这些主题。请记住:如果您不了解任何这些主题,或者不够深入了解,您就不能成为软件开发人员。大量的文章和书籍都解释和过度解释。



顺便说一下,你的代码样本甚至都不会编译。你需要了解如何宣布仿制药。



学完它之后,理解使用这两种东西不会有问题。



请参阅:

http://msdn.microsoft.com/en-us/library/ms172192%28v=vs.110%29.aspx [ ^ ],

http://msdn.microsoft.com/en-us/library/87d83y5b.aspx [ ^ ],

http://msdn.microsoft.com/en-us/library/ms173156.aspx [ ^ ]。



还请看我过去的回答接口上的rs:

对接口的怀疑 [ ^ ],

没有过载和过度使用的多态性 [ ^ ],

接口和多态性 [ ^ ],

如何决定选择抽象类或接口 [ ^ ],

抽象类和接口之间的区别,如果它们具有相同的no方法和var [ ^ ],

当我们使用抽象时和使用界面时......? [ ^ ]。



-SA
These are two unrelated topics: generics and interfaces. Both things are related to fundamentals and need a lot of time to explain properly. Just learn each of these topics separately. Remember: you cannot be a software developer if you don't understand any of these topics, or understand not deeply enough. Everything is explained and overexplained in huge number of articles and books.

By the way, your code sample won't even compile. You need to learn how generics are declared.

After you learn it, understanding using both things together won't be a problem.

Please see:
http://msdn.microsoft.com/en-us/library/ms172192%28v=vs.110%29.aspx[^],
http://msdn.microsoft.com/en-us/library/87d83y5b.aspx[^],
http://msdn.microsoft.com/en-us/library/ms173156.aspx[^].

Please also see my past answers on interfaces:
Doubts on Interfaces[^],
POLYMORPHISM WITHOUT OVERLOADING AND OVERRRIDING IS POSSIBLE[^],
Interfaces and Polymorphism[^],
How to decide to choose Abstract class or an Interface[^],
Difference between abstract class and interface if they have same no of methods and var[^],
When we use abstract and when we use interface...?[^].

—SA


这篇关于什么是接口的使用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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