Giter Club home page Giter Club logo

cpp-workshops's Introduction

Full credit to https://github.com/codecop/Book-Discounts-Refactoring-Kata. I only translate the kata to C++.

Book Discounts Refactoring Kata

Exercises to practice refactoring coupled hierarchies.

Domain: Book Discounts Sub System

This code is part of the software system of our book store. The given sub system deals with adding different goodies to orders of books when delivering, e.g. discounts, promotions or gifts.

The current hierarchy of classes is

         CartAble
            |     \
            |      \
            |        DiscountVoucher
       AbstractItem      
      /             \
     /               \
AbstractItemOnOffer    Book & GiftWrapping
         |
         |
    PromotedBook

Classes

CartAble marks items like books and other services like vouchers or gift options which can be put into the shopping cart.

AbstractItem is the base class of all our physical items. Most items are books but we also offer other things like gift cards.

Book is the most used item. A book has a weight which causes delivery costs.

AbstractItemOnOffer is for items (i.e. books) which can be on offer. Items on offer

  • Allow for a discount on delivery cost.
  • Allow for gift options.
  • Reduce the cost of delivery if you are buying two or more of the same kind.

PromotedBook is a concrete book on promotion with several goodies:

  • You get a 10% discount on your next purchase.
  • You get a discount on delivery if it is heavy.
  • You get a gift wrapping for free.

Exercise

This exercise is hard. It includes several classes which form a coupled hierarchy. Maybe start exploring a simpler code base first, which only has one level of hierarchy.

Your Task

Favour composition over inheritance is a common phrase. Remove all hierarchies and refactor the code to only use composition. (Implementing interfaces is allowed.)

Motivation

We want an exercise for working with deep inheritance hierarchies. We need at least

  • 4-5 levels of hierarchy
  • mutation on some levels
  • 1 method calling some superclass methods
  • override of some superclass methods in subclasses

License

BSD 3-Clause License, see LICENSE in repository.

cpp-workshops's People

Contributors

vmille avatar

Watchers

 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.