Skip to main content

应用程序接口

应用程序接口(英语:Application Programming Interface,简称:API),又称为应用编程接口,就是软件系统不同组成部分衔接的约定。由于近年来软件的规模日益庞大,常常会需要把复杂的系统划分成小的组成部分,编程接口的设计十分重要。程序设计的实践中,编程接口的设计首先要使软件系统的职责得到合理划分。良好的接口设计可以降低系统各部分的相互依赖,提高组成单元的内聚性,降低组成单元间的耦合程度,从而提高系统的维护性和扩展性。
目录

    1 概要
    2 API种类
        2.1 API in object-oriented languages
        2.2 API libraries and frameworks
        2.3 API and protocols
        2.4 API and device interfacing
        2.5 Web APIs
    3 API的开发样例代码
    4 参考文献
    5 外部链接
    6 参见

概要

应用程序接口为:“‘电脑操作系统(Operating system)’或‘程序库’提供给应用程序调用使用的代码”。其主要目的是让应用程序开发人员得以调用一组例程功能,而无须考虑其底层的源代码为何、或理解其内部工作机制的细节。API本身是抽象的,它仅定义了一个接口,而不涉入应用程序如何实现的细节。

例如,图形库中的一组API定义了绘制指针的方式,可于图形输出设备上显示指针。当应用程序需要指针功能时,可在引用、编译时链接到这组API,而运行时就会调用此API的实现(库)来显示指针。

应用程序接口是一组数量上千、极其复杂的函数和副程序,可让程序员做很多任务作,譬如“读取文件”、“显示菜单”、“在视窗中显示网页”等等。操作系统的API可用来分配存储器或读取文件。许多系统应用程序借由API接口来实现,像是图形系统、数据库、网络Web服务,甚至是联机游戏。

应用程序接口有诸多不同设计。用于快速执行的接口通常包括函数、常量、变量与数据结构。也有其它方式,如通过解释器,或是提供抽象层以屏蔽同API实现相关的信息,确保使用API的代码无需更改而适应实现变化。

应用程序接口经常是软件开发工具包(SDK)的一部分。
API种类

API又分为(Windows、Linux、Unix等系统的)系统级API,及非操作系统级的自定义API。作为一种有效的代码封装模式,微软视窗(windows)的API开发模式,已经为许多商业应用开发的公司所借鉴,并开发出某些商业应用系统的API函数予以发布,方便第三方进行功能扩展。如Google、苹果电脑公司,以及诺基亚等手机开发的API,等等。
API in object-oriented languages

    en:List of Java APIs

API libraries and frameworks

    Windows API
    微软Windows的DirectX
    Simple DirectMedia Layer(SDL)

API and protocols

    en:LDAP Application Program Interface

API and device interfacing

    PC BIOS调用接口
    ASPI for SCSI device interfacing

Web APIs

    主条目:Web service

    Google地图的API
    MediaWiki API


API的开发样例代码

API的应用开发需要按照API发布者提供的的规范进行开发。

比如,以下两个例子是Windows API在各编程语言中的表达方式:

    Visual Basic

[Public|Private] Declare Function|Sub name Lib "libname" [Alias "aliasname"]([[Byval] variable [As type][,[Byval] variable [As type]]...]) [As type]

    C#(C Sharp)

[DllImport("libname", 'Named Parameters')]
[public|private|internal] [Type] FunctionName(Type parameter1,Type parameter2...);

Comments

Popular posts from this blog

CKA Simulator Kubernetes 1.22

  https://killer.sh Pre Setup Once you've gained access to your terminal it might be wise to spend ~1 minute to setup your environment. You could set these: alias k = kubectl                         # will already be pre-configured export do = "--dry-run=client -o yaml"     # k get pod x $do export now = "--force --grace-period 0"   # k delete pod x $now Vim To make vim use 2 spaces for a tab edit ~/.vimrc to contain: set tabstop=2 set expandtab set shiftwidth=2 More setup suggestions are in the tips section .     Question 1 | Contexts Task weight: 1%   You have access to multiple clusters from your main terminal through kubectl contexts. Write all those context names into /opt/course/1/contexts . Next write a command to display the current context into /opt/course/1/context_default_kubectl.sh , the command should use kubectl . Finally write a second command doing the same thing into ...

OWASP Top 10 Threats and Mitigations Exam - Single Select

Last updated 4 Aug 11 Course Title: OWASP Top 10 Threats and Mitigation Exam Questions - Single Select 1) Which of the following consequences is most likely to occur due to an injection attack? Spoofing Cross-site request forgery Denial of service   Correct Insecure direct object references 2) Your application is created using a language that does not support a clear distinction between code and data. Which vulnerability is most likely to occur in your application? Injection   Correct Insecure direct object references Failure to restrict URL access Insufficient transport layer protection 3) Which of the following scenarios is most likely to cause an injection attack? Unvalidated input is embedded in an instruction stream.   Correct Unvalidated input can be distinguished from valid instructions. A Web application does not validate a client’s access to a resource. A Web action performs an operation on behalf of the user without checkin...