Difference between SPI and API?

前端 未结 9 1116
旧巷少年郎
旧巷少年郎 2020-11-28 00:21

What is the difference between Service Provider Interface (SPI) and Application Programming Interface (API)?

More specifically, for Java libraries, what makes them a

9条回答
  •  挽巷
    挽巷 (楼主)
    2020-11-28 00:33

    NetBeans' FAQ: What is an SPI? How is it different from an API?

    API is a general term - an acronym for Application Programming Interface - it means something (in Java, usually some Java classes) a piece of software exposes, which allows other software to communicate with it.

    SPI stands for Service Provider Interface. It is a subset of all things that can be API specific to situations where a library is providing classes which are called by the application (or API library), and which typically change the things the application is able to do.

    The classic example is JavaMail. Its API has two sides:

    • The API side — which you call if you are writing a mail client or want to read a mailbox
    • The SPI side if you are providing a wire-protocol handler to allow JavaMail to talk to a new kind of server, such as a news or IMAP server

    Users of the API rarely need to see or talk to the SPI classes, and vice-versa.

    In NetBeans, when you see the term SPI, it is usually talking about classes that a module can inject at runtime which allow NetBeans to do new things. For example, there is a general SPI for implementing version control systems. Different modules provide implementations of that SPI for CVS, Subversion, Mercurial and other revision control systems. However, the code that deals with files (the API side) does not need to care if there is a version control system, or what it is.

提交回复
热议问题