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

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

问题描述

我们通常在项目中使用抽象函数/接口.为什么真的需要它?为什么我们不能只去业务逻辑层、数据访问层和表示层

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

表示层的功能:

abc();

<小时>

业务逻辑层的功能:

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

<小时>

数据访问层的功能:

public abstract void abc();

<小时>

数据访问 SQLServer 层中的功能:

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

<小时>

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

推荐答案

通常,如果您在代码中使用接口,那么您将通过依赖注入的形式获得代码可操作性.

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天全站免登陆