为什么在我们的项目所需要的接口层/抽象类? [英] Why Interface Layer/Abstract classes required in our project?

查看:142
本文介绍了为什么在我们的项目所需要的接口层/抽象类?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们通常在我们的项目中使用抽象的函数/接口。为什么它是真正需要的?为什么我们不能只是去业务逻辑层,数据访问层和presentation层仅

We normally use abstract function/Interfaces in our projects. Why it is really needed? Why can't we just go for Business logic Layer, Data Access Layer and Presentation Layer only

在presentation层功能:

abc();


功能在业务逻辑层:

 public void abc()
    {
      //Preparing the list
    }


功能在数据访问层:

public abstract void abc();


功能在数据访问的SQLServer层:

 public override void abc()
    {
       //Connection with database
    }


的问题是:为什么需要数据访问层

推荐答案

一般来说,如果你在你的code使用的接口,那么你将获得code manuverability的依赖注入的形式。

Generally, if you use interfaces in your code, then you will gain code manuverability in the form of Dependency Injection.

这将帮助你在单元测试过程中替换例如提供Mock对象某些特定的情况实现的部分。

This will help you replace parts of your implementation in certain situations for example providing Mock objects during Unit Testing.

这篇关于为什么在我们的项目所需要的接口层/抽象类?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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