are boxed at compile time • Classes are derived from Any (Or Any?) • Not covered in this session ◦ Nullable classes are derived from Any? ◦ Nothing is also something but it’s not Any ◦ Generics
String, val lastName: String) { fun fullName(): String = "$firstName $lastName" } interface Person { val age: Int fun fullName(): String } abstract class Person(val firstName: String, val lastName: String) { abstract fun fullName(): String } • Interfaces • Abstract Classes
Person { ALEX { override fun sayName() = "Alex" }, DOR { override fun sayName() = "Dor" }, IGOR { override fun sayName() = "Igor" }; abstract fun sayName(): String }
fullName(): String = "${sayName()} Dylan" } class BobDole(override val firstName: String = "Bob", val lastName: String = "Dole"): Bob(firstName) { override fun fullName(): String = "I'm Bob Dole" } abstract class Bob(open val firstName: String): Person { abstract fun fullName(): String //can be omitted (from person) fun sayName(): String = "My Name Is $firstName" }
“by” keyword which will get its own talk OCP - Open/Closed Principle LSP - Liskov Substitution Principle ISP - Interface Segregation Principle DIP - Dependency Inversion Principle - named and default parameters
fun writeCode() = "I Write code in $language" } open class JavaDeveloper(otherLanguage: String) : Developer(otherLanguage) { open val version = "9" constructor(): this("Java") //Secondary Constructor override fun writeCode(): String = writeJavaCode() protected open fun writeJavaCode() = "public static void main(String[] args)" } class KotlinDeveloper: JavaDeveloper("Kotlin") { override val version: String = "1.1" override fun writeJavaCode(): String = writeKotlinCode() private fun writeKotlinCode(): String = "fun main(args: Array<String>)" }
JavaProgrammer { open val version = "9" constructor(): this("Java") override fun writeCode(): String = writeJavaCode() override fun writeJavaCode() = "public static void main(String[] args)" }