5f. UML Elements - Interface
It's time we jump into more advanced elements. So let's start talking about Interfaces.
What is an Interface?
"An Interface specifies a contract; any instance of a Classifier that realizes the Interface shall fulfill that contract…Interfaces may not be instantiated. Instead, an Interface specification is implemented or realized by a BehavioredClassifier, which means that the BehavioredClassifier presents a public facade that conforms to the Interface specification."
To explain the purpose of an Interface, let's use the analogy of a course certificate of completion on your professional profile. A certificate of completion is meant to signify to all who read your profile that you have a certain kill or ability and that other can rely on you for that skill or ability. It is somewhat of a way of saying, “I am a possessor of a specific capability or characteristic.”
Interfaces are like the certificate in this analogy. Classes that realize (or implement) those Interfaces are essentially saying that they have the structure and behaviors that the Interface requires and as such can be treated as if it were that Interface.
Interfaces are almost exactly identical to Classes in that they have attributes and operations and can participate in associations or generalization relationships. The biggest difference is that they are considered fully "abstract" and as such cannot be used to create instances. What this means is that the only way for there to be instances that are "types of" or "instances of" that Interface is if a Class realizes that Interface which is instantiated.
An Interface looks and acts almost exactly like a Class, except with the "«interface»" keyword above the name.

Comparison to Object-Oriented Programming Languages
Interfaces are known by "interface" and "contract" in some Object-oriented programming languages. They have the same meaning and semantics as with UML Interfaces. Programming languages differ in their support for attributes, generalization, and other features.
How do you know when to define a new Interface?
We talked previously about the concept of "composition over inheritance" in the last lesson about Generalizations. Interfaces and InterfaceRealizations are one way to achieve composition better than with inheritance.
One convention that is sometimes useful is to think of Interfaces as things that end in "able". When you are trying to decide on whether something should be an Interface or even what to name your interface, you can use this convention. For example, "Executable", "Comparable", "Serializable", etc. can all be ways to isolate the attributes or operations that you want in an Interface and how to name it.
Abstract Syntax
To illustrate what an Interface is, UML provides abstract syntax which we have recreated in UML Class Diagrams.


