Kata01: Supermarket Pricing - CodeKata
This kata arose from some discussions we've been having at the DFW Practioners meetings. The problem domain is something seemingly simple: pricing goods at supermarkets.
Some things in supermarkets have simple prices: this can of beans costs $0.65. Other things have more complex prices. For example:
Seems Good:
https://github.com/koert/code-kata-supermarket
For Reference:
https://github.com/amarnus/code-kata/tree/master/supermarket-pricing
https://github.com/riversx/Kata-SuperMarketPricing-CS-Legacy/tree/master/SuperMarketPricingKata/SuperMarketPricingKata
http://nimblepros.com/media/36760/supermarket%20pricing%20kata.pdf
Read full article from Kata01: Supermarket Pricing - CodeKata
This kata arose from some discussions we've been having at the DFW Practioners meetings. The problem domain is something seemingly simple: pricing goods at supermarkets.
Some things in supermarkets have simple prices: this can of beans costs $0.65. Other things have more complex prices. For example:
- three for a dollar (so what's the price if I buy 4, or 5?)
- $1.99/pound (so what does 4 ounces cost?)
- buy two, get one free (so does the third item have a price?)
I used three patterns in my solution: Composite, Decorator, and the Null Object. Composite allows a collection of objects to be treated like one of the objects itself. A LEGO construct is a group of individual LEGOs, but as far as attaching another LEGO, the construct can be thought of as being a single, giant, complex LEGO.
The Decorator pattern embellishes the behavior of an object. Wrapping paper can decorate a box and turn it into a gift. A silicone mit can decorate a hand and keep it from getting burned when grabbing a hot pizza pan out of the oven.
The Null Object pattern establishes a definition for a “null” or empty object. It allows us to gracefully handle situations where there’s no special behavior needed.
http://blog.quarternotecoda.com/blog/2011/10/14/code-kata-1-supermarket-pricing/Seems Good:
https://github.com/koert/code-kata-supermarket
For Reference:
https://github.com/riversx/Kata-SuperMarketPricing-CS-Legacy/tree/master/SuperMarketPricingKata/SuperMarketPricingKata
http://nimblepros.com/media/36760/supermarket%20pricing%20kata.pdf
Read full article from Kata01: Supermarket Pricing - CodeKata