Design-Patterns-In-Kotlin
Design-Patterns-In-Kotlin copied to clipboard
Add FlyWeight pattern
Sorry for the two PRs instead of one.
I have a problem with understanding pattern based on this example.
See this one: https://github.com/ochococo/Design-Patterns-In-Swift#-flyweight
Where the same instance of coffee is used in two different contexts and objects are created on the fly.
Okay, I will rewrite the example from Swift to Kotlin when I get home.
Sorry for this late comment. What do you mean the same instance is used in two different contexts?
let coffeeShop = CoffeeShop(menu: Menu())
coffeeShop.takeOrder(origin: "Yirgacheffe, Ethiopia", table: 1)
coffeeShop.takeOrder(origin: "Yirgacheffe, Ethiopia", table: 3)
coffeeShop.takeOrder(origin: "Buziraguhindwa, Burundi", table: 3)
coffeeShop.serve()
By context, I meant "table" in above the example. "Yirgacheffe, Ethiopia" instance would get created once and used by 2 (or more) tables.