October 2019
Intermediate to advanced
434 pages
11h 54m
English
A class can implement multiple interfaces. This is one way in which composition can be achieved in Kotlin. Rather than belonging to strict inheritance hierarchies, all classes can implement interfaces that define specific behaviors.
To add multiple interfaces to the class declaration, separate the interface names by commas, as shown in the following code:
class Player : Movable, Drawable { override fun update(currentTime: Long) { // add logic } override fun move(currentTime: Long) { // add logic } override fun draw() { // add logic }}
In this example, we've added a Drawable interface to our Player class, which already implements Movable.
What happens if two interfaces include the same method signature? In ...
Read now
Unlock full access