Interface definition

There is something that is not clear to me conceptually. When the term interface is referred to what exactly does it refer to?

I have seen that they can refer to this as methods of a class or a purely abstract class that only contain methods without their implementation.

 7
Author: Ernesto Lacalle, 2016-08-30

3 answers

In Object-Oriented Programming theory, where everything is an object and objects communicate with each other through messages.

The interface is the messages that an object can respond to (it is also known as a protocol).

In a pure class-based Object-Oriented Language, the interface is given by the Class / S to which the object belongs.

In a pure object-oriented language based on prototypes, there is nothing left but to parse the object in yes to know what messages you accept.

In languages such as Java or C#, Constructions of type Interface, follow this idea, that is, define which methods (messages) must respond to a class that implements it (the interface) and are a mechanism to deal with multiple inheritance.

For interface examples look at the response of fredyfx.

Reference: notes by Alan Kay on the definition of object-oriented .

Alan Kay is the father of Smalltalk, considered the first object-oriented programming language.

 7
Author: El Asiduo, 2016-09-02 04:43:42

At least in the case of C # an interface is nothing more than a contract composed of methods and properties declared with the keyword interface, all those classes that implement the interface must necessarily complete the methods exposed in it.

Https://msdn.microsoft.com/es-es/library/87d83y5b.aspx

 5
Author: David Porqueras, 2016-08-30 07:59:35

Let's understand this concept with a real-life example:

Means of Transport: auto, airplane, boat: all 3 accelerate, brake, have a steering control (handlebar / steering wheel), but the way they do it is different. Here you define an interface with the 3 mentioned elements whose implementation is different.

An interface is a" implementation contract "between classes, where classes are grouped by what" do ", as opposed to the inheritance that groups classes by "what they are".

 5
Author: fredyfx, 2016-09-02 15:38:56