Skip to content

Instantly share code, notes, and snippets.

@Serchinastico
Created September 12, 2018 13:28
Show Gist options
  • Save Serchinastico/75b44e3e152fc263ba41388ee6998f4a to your computer and use it in GitHub Desktop.
Save Serchinastico/75b44e3e152fc263ba41388ee6998f4a to your computer and use it in GitHub Desktop.
Interfaces exercise in kotlin
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