当前位置: 首页 > news >正文

How to use Interface

Interface

 

In OO world , interface is a very important role whichis responsible for connected classes or architect layers .in another word ,it’s the classes or the architecture’s bridge .

 

With Interface , Classes can “talk”

 

How does class talk ?

Without interface , as we know ,if class1 want to callclass2 method or use class2 something , it will new a instance of class2 like :

var c2 = new class2();

what’s wrong , class1 know class2 too much .in anotherword , class1 should tell class2 what he need ,but not ask class2 to dosomething for him .

so need interface .


 


Class1 “tell” what he want to class2 , then class2 doit .

Then How does class1 get what he need ?

 

Dependency injection . How?

1.    Constructor

2.    Method

3.    Setter

Usually , We use constructor :

 

 

As We can see, interface perfectly be the bridge between two classes who need to “talk

AnotherInterface usage is to connect two architect layers .

 

A sampleASP.NET project structure .






Conclusion :

when you need to call some method , do not new the class , but list what you want (we call itinterface ), then let other class implement it.Then by dependency injection get the interface do whatever you need .

相关文章:

  • 无需第三方软件 用ScreenToaster在线进行视频录制
  • 将你的收藏共享给QQ好友
  • 你不在线,文件我照样传
  • 轻松发送语音邮件
  • linux下C编程详解
  • 资金头寸是什么?
  • Meizu M8 SDK开发初体验
  • Asp.net interview question
  • 有“备”才能无患——数据备份层层渗入 07
  • jTemplate Sample
  • 自己动手丰衣足食——自架最经济的博客服务器 07
  • 快速找回误删数据(图文攻略)
  • 自主服务器建博客有何好处? 07
  • Cross site request in Jquery
  • 虎哥推荐 07
  • Asm.js的简单介绍
  • JS+CSS实现数字滚动
  • Js基础知识(一) - 变量
  • macOS 中 shell 创建文件夹及文件并 VS Code 打开
  • mac修复ab及siege安装
  • Node + FFmpeg 实现Canvas动画导出视频
  • nodejs调试方法
  • Nodejs和JavaWeb协助开发
  • Spring Cloud中负载均衡器概览
  • Storybook 5.0正式发布:有史以来变化最大的版本\n
  • Vue.js 移动端适配之 vw 解决方案
  • 阿里云ubuntu14.04 Nginx反向代理Nodejs
  • 从地狱到天堂,Node 回调向 async/await 转变
  • 从输入URL到页面加载发生了什么
  • 基于HAProxy的高性能缓存服务器nuster
  • 前端js -- this指向总结。
  • 实战|智能家居行业移动应用性能分析
  • 通信类
  • C# - 为值类型重定义相等性
  • 宾利慕尚创始人典藏版国内首秀,2025年前实现全系车型电动化 | 2019上海车展 ...
  • 如何在 Intellij IDEA 更高效地将应用部署到容器服务 Kubernetes ...
  • ​iOS安全加固方法及实现
  • ​RecSys 2022 | 面向人岗匹配的双向选择偏好建模
  • ​软考-高级-系统架构设计师教程(清华第2版)【第9章 软件可靠性基础知识(P320~344)-思维导图】​
  • ​水经微图Web1.5.0版即将上线
  • ​一文看懂数据清洗:缺失值、异常值和重复值的处理
  • $Django python中使用redis, django中使用(封装了),redis开启事务(管道)
  • ( 10 )MySQL中的外键
  • (07)Hive——窗口函数详解
  • (多级缓存)缓存同步
  • (附源码)springboot美食分享系统 毕业设计 612231
  • (六)激光线扫描-三维重建
  • (四)docker:为mysql和java jar运行环境创建同一网络,容器互联
  • (原創) 未来三学期想要修的课 (日記)
  • (源码版)2024美国大学生数学建模E题财产保险的可持续模型详解思路+具体代码季节性时序预测SARIMA天气预测建模
  • (转) Face-Resources
  • (转)关于pipe()的详细解析
  • *2 echo、printf、mkdir命令的应用
  • .htaccess 强制https 单独排除某个目录
  • .java 9 找不到符号_java找不到符号