接口VS API VS公共类 [英] Interfaces VS APIs VS Public classes

查看:113
本文介绍了接口VS API VS公共类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对这三个术语的含义和区别有些困惑.

I am a little bit confused about the meaning and the differences between these three terms.

  1. 接口
  2. API
  3. 公共课

我之前问过API和Public类之间是否有区别.这是问题: 公共方法与公共API

I asked before if there is any difference between APIs and Public classes. Here is the question: Public methods vs public APIs

我明白了,但是现在有了新概念 Interface ,我又对接口和API与Public类之间的区别感到困惑,因此,让我们更清楚地了解一下这句话:

I got it, but now with the new concept Interface, I got confused again about the differences between Interface and API and Public class, so to make things clearer, let's see this sentence:

信息隐藏使开发人员可以分别处理模块,而无需其他开发人员知道他们正在处理的模块的实现细节.而是通过其界面使用该模块.

Information hiding allows developers to work on modules separately, without needing other developers to know the implementation details of the module they are working on. The module is instead used through its interface.

接口在这里是什么意思?和公共课一样吗?

What is the meaning of interface here? Is it the same as public class?

推荐答案

这些术语造成混淆的一个主要原因是,它们是Java中的关键字,并且在与语言无关的一般上下文中具有含义.在编程的一般上下文中,这些术语的含义与Java中特定关键字的含义略有不同.

A big reason these terms are confusing is because they are keywords in Java and they have meaning in a general, language-agnostic context. What the terms mean in the general context of programming is slightly different from what the specific keywords mean in Java.

通常,术语接口抽象同义.当您阅读时,编程到接口"它意味着将程序抽象化.在Java中,interface关键字指示特定类型的无状态抽象,这与abstract class形成对比.通常,这两个都是抽象的,因此都是编程接口.

In general, the term interface is synonymous with abstraction. When you read, "Program to an interface" it means program to an abstraction. In Java, the interface keyword indicates a specific type of stateless abstraction, which is contrasted with abstract class. In general, both of these are abstractions and thus both are programming interfaces.

通常,术语 public 表示开发团队外部的客户可见和使用的任何代码部分.在Java中,public关键字指示类和成员之间的特定访问级别.由于客户也可以查看和使用protected成员,因此在编程的一般情况下,也可以将这些成员视为 public .有效的Java使用术语 exported 来组合publicprotected成员.请注意,在Java 9+中,可以使用模块来控制访问,因此即使public类也可能无法导出,因此从一般意义上讲可能不是 public .

In general, the term public indicates any part of code that is visible to and used by clients outside of the development team. In Java, the public keyword indicates a specific access level between classes and members. Since clients may view and use protected members as well, these may also be considered public in the general context of programming. Effective Java uses the term exported to combine public and protected members. Note that in Java 9+ modules can be used to control access, so even public classes may not be exported and thus may not be public in the general sense.

术语 API 不是Java关键字,因此至少我们没有针对特定语言的歧义.它通常用于表示公共API ,它与导出的API 同义.它是您(开发人员)允许客户查看和使用的所有内容的总和.有时,术语内部API 用来表示相反的含义:您不允许客户端查看或使用的类和成员.

The term API is not a Java keyword, so at least we have no language-specific ambiguity to contend with. It is typically used to mean public API, which is synonymous with exported API. It is the sum of everything that you (the developer) allow your clients to view and use. Occasionally, the term internal API is used to indicate the opposite: classes and members that you do not allow your clients to view or use.

这篇关于接口VS API VS公共类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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