user5922471
user5922471

Reputation: 33

Differencce between interface and API

could you please explain the difference between interface and API?

I was looking for this information here and using google but I only find a special information for Oracle.

What I'm looking for is the general difference.

Much appreciated!

Update: thank you all for the answers. My question was kept deliberately general because I 1) do not have the detailed information about the used programming languages (question based on a short information about one vendor's implementation in my project); 2) I wanted to understand the general high-level difference between the both terms.

Upvotes: 1

Views: 1421

Answers (2)

GhostCat
GhostCat

Reputation: 140427

Without further context, your question is a bit broad; but lets try; by looking up the definition of API on wikipedia:

In computer programming, an application programming interface (API) is a set of subroutine definitions, protocols, and tools for building software and applications.

Then: API stands for application programming interface; indicating that well, an API contains all elements (plural!) required to create an application which wants to interact with the component behind that API.

Whereas an interface in its stricter sense typically denotes a "single specific entity"; like the List interface in java describes an ordered collection (without providing details about specific implementation).

But of course, there are certain commonalities - both terms are about the description of the "boundary" of a "system". Long story short: there is simply no sharp, precise separation between those two concepts. Thus, when using those words within a group of people, you might want to first "step back" and discuss terminology - to ensure that all people involved have the same understanding of such terms. Or as DDD puts it: you want to create a Ubiquitous Language in which such terms have a clear, well defined meaning.

Finally: it is also worth mentioning that the term interface has different meanings when using different programming languages. In Java, an interface is really a concept embodied within the language core; where as in C++, an "interface" would probably be seen as the content of a single header file; leading to subtle but important "flavors" of "interface" for those two languages.

Edit:

  1. Both, interface and API should not expose (too much?!) of the internals to the outside world.
  2. Generally speaking, an API outlines a "component" (a complete "application" for example); whereas an interface might outline a "smaller" entity".
  3. For your other refinement, about one company providing the API, and another the interface - I cant say anything. Because; as others have explained too: the definitions for those terms are really to unclear/fuzzy. We would need to know much more about the application and its requirements to even comment on your statement here.

Upvotes: 3

Mike Nakis
Mike Nakis

Reputation: 61986

The question "what is the difference between X and Y" is only meaningful when X and Y have single meanings and strict definitions. But "interface" and "API" do not have either single meanings nor strict definitions, so one cannot tell what is the difference between them.

For the most part, there is no difference, but there exist certain contexts where one would be suitable to use, while the other would be less suitable, or even unsuitable.

So, for example, a class implements an interface, never an API. On the other hand, an entire software system is more likely to be said to expose APIs rather than interfaces, though to say interfaces in this case would not be wrong either.

I wish there was some easy distinction, like "interfaces are small-scale, APIs are large-scale", or "interfaces are more specific, APIs are more nebulous", but there is no such distinction.

Upvotes: 2

Related Questions