Last active
July 13, 2018 02:59
-
-
Save esirK/fd682c088e1c1f87f1923c7a3113c56e to your computer and use it in GitHub Desktop.
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
fun main(args: Array<String>) { | |
var beverage: Beverage | |
beverage = Espresso() | |
var beverageWithTopping = Mocha(beverage) | |
//Mocha decorates Espresso | |
println("You bought ${beverageWithTopping.description} Total cost: ${beverageWithTopping.cost()}") | |
//If we decide to add a new topping ontop of Mocha, we just need to wrap the beverageWithTopping inside the Topping e.g | |
beverageWithTopping = Soya(beverageWithTopping) | |
//This will give us a beverage with Soya and Mocha toppings with the descriptions and cost updated automatically. | |
println("You bought ${beverageWithTopping.description} Total cost: ${beverageWithTopping.cost()}") | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment