August 2018
Beginner
178 pages
4h 56m
English
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" ...
Read now
Unlock full access