在类库中创建接口c# [英] Creating an Interface in a class library c#

查看:69
本文介绍了在类库中创建接口c#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想创建一个库项目,它充当一种包装器/中间类,并且我的所有变量/函数都可以在其他类中使用。在这个库中创建一个存储变量的接口是否有效率,或者很容易在库类本身中声明?

I want to create a library project which acts as a sort of wrapper/intermediary class and has all my variables/functions to be used in other classes. Is there any efficiency in creating an interface within this library to store variables or that can easily just be declared in the library class itself?

推荐答案

引用:

我想创建一个库项目,它充当一种包装器/中间类,并且我的所有变量/函数都可以在其他类中使用

I want to create a library project which acts as a sort of wrapper/intermediary class and has all my variables/functions to be used in other classes

为什么?您是否有特定要求(例如,您需要代理)或者您是否看到了这样做的一般优势?







Why? Have you a specific requirement (e.g. you need a proxy) or do you see a general advantage in doing that?



Quote:

在这个库中创建一个存储变量的接口是否有效率,或者可以很容易地在库类本身?

Is there any efficiency in creating an interface within this library to store variables or that can easily just be declared in the library class itself?

你知道,使用iterfaces没有性能提升。接口在面向对象编程中扮演着非常特殊的角色,如果您有任何疑问,那么我建议您学习一本好的OOP书(或者至少在网上阅读好的教程)。

You know, there is no performance gain in using iterfaces. Interface has a very specific role in Object Oriented Programming, if you have any doubt then I suggest you studying a good OOP book (or, at least, read goodtutorials on the web).


接口无法存储任何东西,您仍然需要将属性存储在具体类中。只有在您可以看到需要存储属性的类的不同具体实现时,才能使用接口。由于我们在这里讨论数据,这是非常不可能的,您通常使用接口,因此您可以使用不同的代码实现,但属性是属性。所以我不打算使用界面。
Interfaces can't store anything, you'll still need the properties to be stored in a concrete class. Interfaces are only of use if you can see you needing different concrete implementations of the class that stores your properties. As we're talking data here, that's very unlikely, you normally use interfaces so you can have different implementations of code, however properties are properties. So I wouldn't bother with an interface.


这篇关于在类库中创建接口c#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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