Interfaces
If you have any experience with any modern language, then you have probably used a type that defines a behavior. These types are called traits in Scala, protocols in Swift, and interfaces in Kotlin, Java, and C#.
An interface is a blueprint or a definition of a type. When a type implements an interface, we can then refer to it by this contract, that is, a set of methods that the type implements.
Here is an interface declaration in Kotlin:
interface Drivable { fun drive() }
The syntax for implementing an interface is the same as for inheritance. In the implementing class header, after a primary constructor or a class name comes the colon and the interface name:
class Car : Drivable { override fun drive() { println("Driving a car") } }
The only difference from inheritance syntax is that we don't call the base type constructor because interfaces don't have one.
The implementing type (unless it is an abstract class) has to implement or override all the members that interface defined...