Giter Club home page Giter Club logo

kata-supermarket-pricing's Introduction

Build Status codecov

kata-supermarket-pricing

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?)

The exercise is to experiment with a model that is flexible enough to deal with these (and other) pricing schemes, and at the same time are generally usable how do you keep an audit trail of pricing decisions.

Implementation choices

In this supermarket, you can buy whatever you wish. there is no stock management, as it was not specified in the subject.

Basically, A customer has got a cart, and is free to buy whatever items he wants, which are then added to the cart. When the customer doesn't need anything else, he goes to the supermarket checkout, which is in charge of calculating the bill incrementally, according to each item found in the cart. The customer's cart is in charge of making sure that the customer doesn't try anything suspicious (i.e. adding a decimal value of an item that is bought in unitary value). I assumed that the supermarket itself would not have such items and then decided to control this directly in the cart addition method.

In terms of structure, I decided to implement a sort of decorator pattern, which decides of the pricing calculation method that is to be applied to an item, according to its properties. Additionnally, the features "Three for a dollar" and "Buy two, get one free" are implemented in a more generic way to the sole "PackagePricing" class. That can be explained by the fact I assumed there was always a unitary price for which you could acquire one unit of desired item. It means that "three for a dollar", is then a specific price applied for getting three units specifically, while the "buy two, get one free", is also a discount of 33% if you get three units. However, getting one unit of the aforementioned item will still result in the price being higher since the reduction won't be applied. Along with the PackagePricing method, there is a DefaultPricing method that includes the "$1.99/pound" calculation. The DefaultPricing method will calculate the price as a flat multiplication of a float and a price, as the customer's cart is in charge of enabling the pricing by weight according to the item selected.

kata-supermarket-pricing's People

Contributors

kmaxime avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.