Skip to content

Instantly share code, notes, and snippets.

@esirK
Last active July 13, 2018 02:59
Show Gist options
  • Save esirK/fd682c088e1c1f87f1923c7a3113c56e to your computer and use it in GitHub Desktop.
Save esirK/fd682c088e1c1f87f1923c7a3113c56e to your computer and use it in GitHub Desktop.
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