In this chapter, we have discussed constructors, which are the buildings blocks of OOP. We've learned how to define interfaces and various classes and the differences between inner
, sealed
, enum
, and data classes. We've learned that all elements are public
by default and all classes/interfaces are final
by default, so we need to explicitly open them to allow inheritance and member overriding.
We've discussed how to define proper data models using very concise data classes combined with even more powerful properties. We know how to properly operate on data using various methods generated by the compiler and how to overload operators.
We learned how to create singletons by using object declarations and how to define objects of an anonymous type that may extend a class and/or implement an interface using object expressions. We've also presented the usage of the lateinit
modifier, which allows us to define non-nullable data types with delayed initialization.
In the next chapter, we will...