Реализации на Kotlin
Decorator
Общая реализация на языке Kotlin
interface ICoffee {
val cost: Int
fun makeCoffee()
}
fun main() {
val simpleCoffee: ICoffee = SimpleCoffee()
simpleCoffee.makeCoffee()
println("Current cost of coffee is: ${simpleCoffee.cost}")
val milkCoffee: ICoffee = MilkDecorator(simpleCoffee)
milkCoffee.makeCoffee()
println("Current cost of coffee is: ${milkCoffee.cost}")
val milkAndSugarCoffee: ICoffee = SugarDecorator(milkCoffee)
milkAndSugarCoffee.makeCoffee()
println("Current cost of coffee is: ${milkAndSugarCoffee.cost}")
}
Last updated
Was this helpful?