Giter VIP home page Giter VIP logo

red-pencil-kata's Introduction

Red Pencil Kata

This repository contains my test-driven and Java-based solution to Stefan Rock's Red Pencil Kata.

Kata Description

As described in Stefan's blog post, the kata prompt is to create rules for automatically activating and deactivating "Red Pencil" promotions for products in an online marketplace. These are month-long (30 day) promotions that begin when a seller reduces the price of a product. Since this system is easily exploitable by sellers to keep their products featured on the marketplace for longer periods than intended, a number of additional rules are imposed on the promotions, including each of the following:

  • The price reduction needs to be at least 5% and at most 30% of the previous price.
  • Additional price reductions during a promotion do not extend the promotion's length.
  • Increasing the price of the product will instantly terminate an active promotion.
  • Decreasing the price of a product so that the new price is less than 30% of its pre-sale price will also end the promotion.
  • Promotions are only activated on a price change if the product's price has been stable for 30 days prior to the price reduction.
  • The minimum length of time between two promotions for the same product is 30 days.

Building and Testing from Source

I've included Gradle wrapper and build configuration files for easy compilation and testing. Accordingly, even without Gradle installed, you can easily build the project from source as follows:

  1. Clone this repository onto your machine

  2. From the project's root directory, run ./gradlew clean build. This should setup the project for you, build class and jar files for the project, and compile and run its JUnit 4 tests.

  3. To rerun the tests, either run ./gradlew test or ./gradlew clean test to ensure that tests are rerun even if no changes have been made to the project.

    Note: On Windows, replace ./gradlew with gradlew.bat in each of these commands.

Possible Project Extensions

I am happy with how my solution turned out and enjoy that it solves the problem while keeping things simple. It is also implemented in such a way that it is readily extended/refactored to accommodate different requests from the client/use cases. A couple natural extensions/redesigns for more complicated requests from the client (which could also be seen as extended programming exercises) are as follows:

  • Replace the Promotion class with a Product decorator. According to the kata prompt, all products are supposed to be eligible for Red Pencil promotions. If this was not the case, especially if there were other optional features for products independent of promotion availability, this could be a good time to implement an abstract ProductDecorator class and replace the current Promotion class with a concrete PromotionDecorator. Implementing the other optional features as decorators would then simplify further development of the online marketplace and also encourage developers to abide by the Single Responsibility Principle.

  • Refactor promotion rules using the Strategy pattern. Given that the online marketplace's owner is concerned about sellers exploiting loopholes in promotion rules, the latter might continually need to be updated and subject to change as sellers come up with new and creative ways to cheat the system. They also could potentially need to vary based on type of product, demand, some metric of seller trustworthiness, product age, other products that are currently promoted, etc.

    If the promotion validation rules turn out to be this variable, encapsulating them into policies would dramatically simplify maintaining and extending the codebase.

red-pencil-kata's People

Contributors

drmrd avatar

Watchers

 avatar  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.