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 来组合public和protected成员.请注意,在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公共类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
07-29 13:34
查看更多