October 2018
Intermediate to advanced
370 pages
9h 15m
English
Interfaces can be implemented by companion objects as well as by normal and object classes. Let's take a look at how this can be done:
data class Employee(val name: String, val id: Int)interface EmployeeInterface{ fun create(name: String, id: Int) : Employee}class EmployeeFactory { companion object : EmployeeInterface{ override fun add(name:String, id: Int): Employee { return Employee(name,id) } }}
This function takes two variables and returns the Employee object.
Read now
Unlock full access