Design-Patterns-In-Kotlin icon indicating copy to clipboard operation
Design-Patterns-In-Kotlin copied to clipboard

Add FlyWeight pattern

Open DeanDonkov opened this issue 5 years ago • 5 comments

DeanDonkov avatar Sep 11 '19 19:09 DeanDonkov

Sorry for the two PRs instead of one.

DeanDonkov avatar Sep 11 '19 19:09 DeanDonkov

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.

dbacinski avatar Sep 25 '19 08:09 dbacinski

Okay, I will rewrite the example from Swift to Kotlin when I get home.

DeanDonkov avatar Sep 25 '19 10:09 DeanDonkov

Sorry for this late comment. What do you mean the same instance is used in two different contexts?

DeanDonkov avatar Oct 01 '19 15:10 DeanDonkov

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.

dbacinski avatar Oct 02 '19 21:10 dbacinski