-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdecorator_pattern.kt
45 lines (34 loc) · 956 Bytes
/
decorator_pattern.kt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
// Decorator Patern
// https://pl.kotl.in/h1AIwrE77
fun main() {
var myStyleOfBrew: Bewrage = DarkRoast()
println(myStyleOfBrew.cost())
myStyleOfBrew = Moca(myStyleOfBrew)
myStyleOfBrew = Moca(myStyleOfBrew)
myStyleOfBrew = Whip(myStyleOfBrew)
println(myStyleOfBrew.cost())
}
class Moca(brew: Bewrage) : Contindment(brew) {
override fun cost() = bewrage.cost() + 1
}
class Whip(brew: Bewrage) : Contindment(brew) {
override fun cost() = bewrage.cost() + 9
}
abstract class Contindment(val bewrage: Bewrage) : Bewrage()
abstract class Bewrage {
private val description: String = "Unknown description"
fun getDescription() = description
abstract fun cost(): Int
}
class HouseBlend : Bewrage() {
override fun cost() = 22
}
class DarkRoast : Bewrage() {
override fun cost() = 7
}
class Decaf : Bewrage() {
override fun cost() = 10
}
class Espresso : Bewrage() {
override fun cost() = 12
}