13

I understand an interface is a set of publicly exposed things that one system can use to interact with others systems. I'm reading about WEBRTC protocol and to understand what a protocol is I went to the Wikipedia definition. It says more or less that a protocol is a system of rules that allows two systems to communicate. Ain't that the same as interface? Maybe I'm not understanding one or both.

4 Answers 4

7

An interface defines how two entities may communicate. A protocol defines how they should communicate and what that communication means.

Here is an interface:

public interface ICommunicate
{
    string SendMessageAndGetResponse(string message);
}

A protocol then might be:

Send "Hello", if you get back "Hi" then send "How are you?" and the response will be a status. If you get back anything other than "Hi" from the initial message then the system is not functioning properly and you must send the message "Reboot" which you'll then get back "Rebooted!" if successful and anything else for failure.

2 Comments

So it seems that a protocol is like a script more than a definition like an interface.
    qwerty
Perhaps a better way to consider the differences from the first two sentences of @Enigmativity's answer is: Interface is a "must" and, in contrast, protocol is a "should."
5

In general interface mean "The point of interconnection or contact between entities." and transferred to software it means "The connection between parts of software." and also "In object-oriented programming, a piece of code defining a set of operations that other code must implement." (Source)

In general protocol means "The official formulas which appeared at the beginning or end of certain official documents such as charters, papal bulls etc." and transferred to computers it means "A set of formal rules describing how to transmit or exchange data, especially across a network.". (Source)

So protocol focuses more on the data exchange, whereas interface focuses more on software interaction independent of any data exchange.

Of course, in the end, software interaction is most of the time a data exchange. Passing arguments to a function is a data exchange. Calling a method/function is not directly a data exchange but you need to imagine it like this: Instead of calling different functions:

c = add(a, b);
c = sub(a, b);

you could as well always call the same function and pass the desired functionality as argument:

c = func("add", a, b);
c = func("sub", a, b);

and that way the functionality becomes data as well.

The terms are somewhat interchangeable. E.g. some programming languages call it interface to focus on the pure interaction of components (classes, objects, etc.) and some call it protocol to focus on the data exchange between the components.

On a network, a protocol is how data is exchanged; think of IP protocol or TCP protocol. But if you have communication endpoints you talk to over a network to trigger functionality, e.g. a REST API, than the sum of all these endpoints and their parameters can be called an interface, while triggering one of the interface functions would be done via a HTTP request and HTTP is a protocol and defines how data is transferred.

Comments

0

I think in some ways the word 'interface' could also be used for this (especially as the I in API), but generally when talking about what we're sending over the wire, the common word is protocol.

When you dive deep enough into exact definitions of words, the meaning and difference can sometimes break down a bit.

But avoiding super exact semantics, API/Interface tends to be a bit higher level than protocol.

Comments

0

Learning from previous answers, I'd suggest that both interface and protocol are things that all sides have to follow so communication/data exchange can happen. The difference is that:

  • Interface aims to reflect the data model of the app and its components
  • Protocol focuses on the rules and procedures during data transmission, usually in network communication

You can explore the relationship between these concepts in Six Degree of Wikipedia:

  • Interface to protocol: enter image description here
  • Protocol to interface: enter image description here

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.