Interfaces

Interfaces are very popular among developers. They are used to decouple the code. Kotlin interfaces are very much like Java 8 interfaces. That means they can have both abstract methods as well as method implementation.

You can declare properties in interfaces. A property declared in an interface can either be abstract, or it can provide implementations for accessors. Properties declared in interfaces can't have backing fields and therefore accessors declared in interfaces can't reference them.

Take a look at our interface AppToolbar.ktwhich deals with the Toolbar. It has got a property that provides a title to the Toolbar and it has a function that initiates it with required data:

    interface AppToolbar {      val toolbar: Toolbar ...

Get Kotlin Blueprints now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.