Instruction

Heads up... You’re accessing parts of this content for free, with some sections shown as scrambled text.

Heads up... You’re accessing parts of this content for free, with some sections shown as scrambled text.

Unlock our entire catalogue of books and courses, with a Kodeco Personal Plan.

Unlock now

Abstract Classes

Sometimes, you may want to prevent a class from being instantiated but still be able to be inherited from. This will let you define properties and behavior common to all subclasses. Such a parent class is called an abstract class. These classes can’t be instantiated, meaning you can’t create an object of an abstract class. You can think of these classes as templates for other classes. Templates, as you know them, are just base style, configurations, and functionality guidelines for a specific design. The template can’t run directly on your website or app. Instead, your app can make use of the template.

Using Interfaces

So far, we’ve been working with the custom type, Class. You’ve learned about inheritance and how a class can extend an abstract and non-abstract class that are related. Another very useful custom type is Interfaces.

Using Kotlin Standard Library Interfaces

The Kotlin standard library provides us with some interfaces and ready-made tools that help with common functionalities. This helps us avoid reinventing the wheel when we want to do some basic operations or when we want a class to abide by a specific contract. One of them is the Comparable interface.

See forum comments
Download course materials from Github
Previous: Introduction Next: Demo