Created
September 12, 2018 13:28
-
-
Save Serchinastico/75b44e3e152fc263ba41388ee6998f4a to your computer and use it in GitHub Desktop.
Interfaces exercise in kotlin
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
interface Sellable { | |
var priceInEuros: Int | |
var priceInDollars: Int | |
get() = (priceInEuros * 1.06).toInt() | |
set(value) { | |
priceInEuros = (value / 1.06).toInt() | |
} | |
} | |
interface Describable { | |
val id: String | |
val name: String | |
val description: String | |
get() = "[$name] - $id" | |
} | |
interface Product : Sellable, Describable | |
class TShirt( | |
override val id: String, | |
override var priceInEuros: Int | |
) : Product { | |
companion object { | |
private const val NAME: String = "T-Shirt" | |
} | |
override val name: String = NAME | |
} | |
class Jeans( | |
override val id: String, | |
override var priceInEuros: Int | |
) : Product { | |
companion object { | |
private const val NAME: String = "Jeans" | |
} | |
override val name: String = NAME | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment