什么是API?什么是应用程序编程接口?

WHAT ARE APPLICATION PROGRAMMING INTERFACES?
什么是应用程序编程接口?
什么是API?

下面是专业解答:
An Application Programming Interface (API) provides an abstraction for a problem and specifies
how clients should interact with software components that implement a solution to that problem.
The components themselves are typically distributed as a software library, allowing them to be used in multiple applications. In essence, APIs define reusable building blocks that allow modular pieces of functionality to be incorporated into end-user applications.

An API can be written for yourself, for other engineers in your organization, or for the development
community at large. It can be as small as a single function or involve hundreds of classes,
methods, free functions, data types, enumerations, and constants. Its implementation can be proprietaryor open source. The important underlying concept is that an API is a well-defined interface that provides a specific service to other pieces of software.

A modern application is typically built on top of many APIs, where some of these can also
depend on further APIs. This is illustrated in Figure 1.1, which shows an example application that
depends directly on the API for three libraries (1 2 3), where two of those APIs depend on the API
for a further two libraries (4 and 5). For instance, an image viewing application may use an API
for loading GIF images, and that API may itself be built upon a lower-level API for compressing
and decompressing data.

API development is ubiquitous in modern software development. Its purpose is to provide a logical
interface to the functionality of a component while also hiding any implementation details. For
example, our API for loading GIF images may simply provide a LoadImage() method that accepts
a filename and returns a 2D array of pixels. All of the file format and data compression details
are hidden behind this simple interface. This concept is also illustrated in Figure 1.1, where client
code only accesses an API via its public interface, shown as the dark section at the top of each box.

人工翻译:
API 提供了对问题的抽象,并且明确了客户(也即调用者,请求者)如何与软件组件交互,这些软件组件实现了对这个问题解决方案。这些组件它们本身是典型的软件库,可以在多个应用程序中使用。
本质上,API定义了可重用的构建块,这个构建块将允许功能化的模块片段成为最终用户(调用者)应用程序的一部分。

API可以为您自己、组织中的其他工程师或整个开发社区编写。它可以小到只有一个函数,也可以涉及数百个类、方法、自由函数、数据类型、枚举和常量。它的实现可以是专有的,也可以是开源的。重要的底层概念是,API是一个定义良好的接口,它为其他软件提供特定的服务。

现代应用程序通常构建在许多api之上,其中一些api还可以依赖于更深一层的API。如图1.1 所示,
这显示了一个直接依赖于三个库(1 2 3)的API的示例应用程序,其中两个API依赖于另外两个库(4和5)的API。例如,一个图像查看应用程序可以使用一个API来加载GIF图像,而该API本身可以构建在一个用于压缩和解压缩数据的低层API之上。

API开发在现代软件开发中无处不在。它的目的是提供组件功能的逻辑接口,同时隐藏任何实现细节。例如,我们用于加载GIF图像的API可以简单地提供一个LoadImage()方法,该方法接受一个文件名并返回一个2D像素数组。所有的文件格式和数据压缩细节都隐藏在这个简单的接口后面。这个概念也在图1.1中得到了说明,其中客户端代码仅通过其公共接口访问API,如图每个方框顶部的黑色部分所示。
在这里插入图片描述

An application that calls routines from a hierarchy of APIs. Each box represents a software library where the dark section represents the public interface, or API, for that library, while the white section represents the hidden implementation behind that API.
从API层次结构中调用例程的应用程序。每个方框代表一个软件库,其中黑色部分代表该库的公共接口或API,而白色部分代表API背后的隐藏实现。

猜你喜欢

转载自blog.csdn.net/bin_bujiangjiu/article/details/113177302