How to extend a class in Kotlin (Inheritance and Extension functions)
In this recipe, we will learn how to extend a class (Inheritance) and how to extend the functionality of a class using Kotlin's Extension functions.
Inheritance is probably the first concept you learn in object-oriented programming. It is a mechanism where a new class is derived from an existing class. Via this, the classes may inherit or acquire the properties and methods of other classes. Extension functions, on the other hand, let us skip creating wrapper for functionality and enable us to add extra functions to the classes. Let's see both of them now.
Getting ready
Since we will be dealing with Android code, it is recommended that you use Android Studio as IDE. The source code can be found in the 1-recycler-view-in-kotlin
branch of the https://gitlab.com/aanandshekharroy/kotlin-cookbook repository.
How to do it…
A class derived from another class is called a subclass, whereas the class from which a subclass is derived is...