博客
关于我
依赖倒置(DIP),控制反转(IOC),依赖注入(DI)
阅读量:273 次
发布时间:2019-03-01

本文共 894 字,大约阅读时间需要 2 分钟。

什么是依赖?

依赖就是一种需要,例如再Dal层做数据处理,而在Bll层要做操作的话,首先要实例化Dal层,然后才能进行操作。这就是Bll层依赖于Dal层,Dal层被Bll层依赖

namespase DAL{   public class Operation   {      public int Add(){}      public int Delete(){}   }}//BLL层若想调用Dal层,首先要对Dal层添加引用,然后实例化Dal层,才能进行操作using DAL;namespace Bll{    public class Operation    {       Operation ope=new Operation();       public int Add()       {         ope.Add();       }     }}

什么是倒置?

面向对象语言程序设计时,高层模块不直接依赖低层模块,二者通过抽象来依赖。依赖抽象,而不依赖具体细节。以前高层直接依赖于低层,现在高层依赖于抽象,细节由第三方工厂决定

namespase IDAL{public inteface IOperation{int Add();int Delete();}}using IDAL;namespase DAL{   public class Operation:IOperation   {      public int Add(){}      public int Delete(){}   }}namespase Factory{ public IOperation GetFactiory(){   //反射}}//using DAL;namespace Bll{    public class Operation    {       IOperation ope=Factory.GetFactiory();       public int Add()       {         ope.Add();       }     }}

 

 

 

 

转载地址:http://bpua.baihongyu.com/

你可能感兴趣的文章
multisim变压器反馈式_穿过隔离栅供电:认识隔离式直流/ 直流偏置电源
查看>>
mysql csv import meets charset
查看>>
multivariate_normal TypeError: ufunc ‘add‘ output (typecode ‘O‘) could not be coerced to provided……
查看>>
MySQL DBA 数据库优化策略
查看>>
multi_index_container
查看>>
MySQL DBA 进阶知识详解
查看>>
Mura CMS processAsyncObject SQL注入漏洞复现(CVE-2024-32640)
查看>>
Mysql DBA 高级运维学习之路-DQL语句之select知识讲解
查看>>
mysql deadlock found when trying to get lock暴力解决
查看>>
MuseTalk如何生成高质量视频(使用技巧)
查看>>
mutiplemap 总结
查看>>
MySQL DELETE 表别名问题
查看>>
MySQL Error Handling in Stored Procedures---转载
查看>>
MVC 区域功能
查看>>
MySQL FEDERATED 提示
查看>>
mysql generic安装_MySQL 5.6 Generic Binary安装与配置_MySQL
查看>>
Mysql group by
查看>>
MySQL I 有福啦,窗口函数大大提高了取数的效率!
查看>>
mysql id自动增长 初始值 Mysql重置auto_increment初始值
查看>>
MySQL in 太多过慢的 3 种解决方案
查看>>