Object-oriented programming in Kotlin

As we discussed in Chapter 3, Understanding Programming Paradigms in Kotlin, Kotlin fully supports Object-Oriented Programming (OOP). This probably comes as no surprise, given the popularity of OOP in modern languages and Kotlin's ties to the JVM and other JVM-based languages such as Java.

OOP in Kotlin shares many similarities with Java, but there are important differences as well, as in the following examples:

Kotlin also aims to adopt learning and best practices from years of Java to make modeling data easier. Toward this goal, Kotlin provides additional modifiers for creating certain families of classes:

As with other aspects of the language, Kotlin also provides mechanisms for reducing the boilerplate required to define and create class instances. Features such as primary constructors, initialization blocks, and secondary constructors provide the flexibility to scale your implementations from very simple class declarations to much more complex cases.