什么是“基于接口的编程”? [英] What exactly is "interface based programming"?

查看:115
本文介绍了什么是“基于接口的编程”?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我经常听到/阅读有关接口编程,但我不清楚这是什么意思。基于界面的编程是一个实际上独立的主题,实际上有书面的书籍吗?如果有的话,任何人都可以推荐任何好的?

I often hear/read about interfaced based programming but I am not exactly clear on what that really means. Is interfaced based programming an actual stand alone topic that actually has books written about it? If so, can anyone recommend any good ones?

我正在阅读基于界面的编程,因为我正在阅读有关好的API是如何设计的,并且想要了解更多。现在我不清楚如何正确地在界面上设计一个API。

I came across interface based programming as I was reading about how good APIs are designed and would like to learn more about it. Right now I am not clear how to properly go about designing an API around interfaces.

任何信息都非常感谢。

推荐答案

这基本上是表示您的依赖关系的接口而不是具体类(或更糟的是静态方法)。因此,如果您的某个课程需要执行身份验证,则应提供一个 IAuthenticator (或任何)。

It's basically a matter of expressing your dependencies in terms of interfaces instead of concrete classes (or worse, static methods). So if one of your classes needs to perform authentication, it should be provided an IAuthenticator (or whatever).

这意味着:


  • 您可以在实现真正的依赖关系之前编写代码

  • 您可以测试通过嘲笑真的很容易(没有模拟课程,这变得丑陋)

  • 很明显你依赖于API而不是实现(即你有松动的耦合)

这篇关于什么是“基于接口的编程”?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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