应该在asp.net中创建第一个接口或类? [英] What should be created first interface or class in asp.net?

查看:90
本文介绍了应该在asp.net中创建第一个接口或类?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们在应用程序中使用接口,但在我们的应用程序中添加它们的正确方法是什么?

我们首先要创建一个接口并声明一个类中所需的所有函数或者我们应该在类中定义所有函数然后在接口中声明它们吗?这是正确的方法吗?

We use interfaces in our application but what is the correct way to add them in our application?
Shall we create an interface first and declare all the functions needed in a class Or Shall we define all our functions inside the class and then declare them in the interface?Whats the correct way?

推荐答案

没有正确的方法可以做到这一点。这是一个鸡和蛋的问题,要么你从鸡(类)或鸡蛋(界面)开始。



我个人开始接口然后写一个具体的类并根据需要调整界面。然后,一旦我关闭了功能,我就可以编写其他具体类了。



请记住,不要为了创建接口而创建接口。只有在需要为其他具体类定义合同时才创建接口。



你也可以创建接口(至少在VS Standard或以上,不确定右键单击一个类并选择Refactor> Extract Interface。
There is no right way to do this. Its a Chicken and Egg problem, either you start with the chicken (class) or the egg (interface).

Personally I start with the interface then write one concrete class and adjust the interface as needed. Then once I get the functionality down, I can write the other concrete classes.

Just keep in mind, don't create interfaces for the sake of creating interfaces. Only create interfaces when you need to define a contract for other concrete classes to implement.

You can also create interfaces (at least in VS Standard or above, not sure about express) by right clicking on a class and selecting Refactor>Extract Interface.


这篇关于应该在asp.net中创建第一个接口或类?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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