Last active
April 6, 2021 13:08
-
-
Save dodalovic/a22baaadc890a7aba33ff5347282198c to your computer and use it in GitHub Desktop.
Decorator pattern 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
package patterns | |
interface CarService { | |
fun doService() | |
} | |
interface CarServiceDecorator : CarService | |
class BasicCarService : CarService { | |
override fun doService() = println("Doing basic checkup ... DONE") | |
} | |
class CarWash(private val carService: CarService) : CarServiceDecorator { | |
override fun doService() { | |
carService.doService() | |
println("Washing car ... DONE") | |
} | |
} | |
class InsideCarCleanup(private val carService: CarService) : CarServiceDecorator { | |
override fun doService() { | |
carService.doService() | |
println("Cleaning car inside ... DONE") | |
} | |
} | |
fun main(args: Array<String>) { | |
val carService = InsideCarCleanup(CarWash(BasicCarService())) | |
carService.doService() | |
} |
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
Doing basic checkup ... DONE | |
Washing car ... DONE | |
Cleaning car inside ... DONE |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment