{"id":18474408,"url":"https://github.com/codecop/book-discounts-refactoring-kata","last_synced_at":"2025-08-24T19:20:00.340Z","repository":{"id":46049777,"uuid":"312710384","full_name":"codecop/Book-Discounts-Refactoring-Kata","owner":"codecop","description":"Exercises to practice refactoring coupled hierarchies.","archived":false,"fork":false,"pushed_at":"2025-03-25T21:39:38.000Z","size":87,"stargazers_count":2,"open_issues_count":0,"forks_count":2,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-03-25T22:26:38.296Z","etag":null,"topics":["exercise","hierarchy","inheritance","object-oriented","refactoring-kata"],"latest_commit_sha":null,"homepage":"","language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-3-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/codecop.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-11-14T00:01:03.000Z","updated_at":"2025-03-25T21:39:43.000Z","dependencies_parsed_at":"2024-11-06T10:48:19.091Z","dependency_job_id":"07e23534-b2c5-4b37-bd8d-0e7b7549e7fa","html_url":"https://github.com/codecop/Book-Discounts-Refactoring-Kata","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/codecop%2FBook-Discounts-Refactoring-Kata","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/codecop%2FBook-Discounts-Refactoring-Kata/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/codecop%2FBook-Discounts-Refactoring-Kata/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/codecop%2FBook-Discounts-Refactoring-Kata/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/codecop","download_url":"https://codeload.github.com/codecop/Book-Discounts-Refactoring-Kata/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253960028,"owners_count":21990793,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["exercise","hierarchy","inheritance","object-oriented","refactoring-kata"],"created_at":"2024-11-06T10:29:23.059Z","updated_at":"2025-05-13T14:30:20.159Z","avatar_url":"https://github.com/codecop.png","language":"C++","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Book Discounts Refactoring Kata\n\nExercises to practice refactoring coupled hierarchies.\n\n## Domain: Book Discounts Sub System\n\nThis code is part of the software system of our book store. The given sub system\ndeals with adding different goodies to orders of books when delivering, e.g. \ndiscounts, promotions or gifts.\n\nThe current hierarchy of classes is\n \n             CartAble\n                |     \\\n                |      \\\n                |        DiscountVoucher\n           AbstractItem      \n          /             \\\n         /               \\\n    AbstractItemOnOffer    Book \u0026 GiftWrapping\n             |\n             |\n        PromotedBook\n\n### Classes\n\n`CartAble` marks items like books and other services like vouchers or gift options which can be put into the shopping cart.\n\n`AbstractItem` is the base class of all our physical items. Most items are books but we also offer other things like gift cards.\n\n`Book` is the most used item. A book has a weight which causes delivery costs.\n\n`AbstractItemOnOffer` is for items (i.e. books) which can be on offer. Items on offer\n\n* Allow for a discount on delivery cost.\n* Allow for gift options.\n* Reduce the cost of delivery if you are buying two or more of the same kind.\n\n`PromotedBook` is a concrete book on promotion with several goodies:\n\n* You get a 10% discount on your next purchase.\n* You get a discount on delivery if it is heavy.\n* You get a gift wrapping for free.\n\n## Exercise\n\nThis exercise is hard. It includes several classes which form a coupled hierarchy.\nMaybe start exploring a simpler code base first, which only has one level of hierarchy.\n\n### Your Task\n\n*[Favour composition over inheritance](https://stackoverflow.com/questions/49002/prefer-composition-over-inheritance)*\nis a common phrase. Remove all hierarchies and refactor the code to only use composition. \n(Implementing interfaces is allowed.)\n\n### Motivation\n\nWe want an exercise for working with deep inheritance hierarchies. We need at least\n\n* 4-5 levels of hierarchy\n* mutation on some levels\n* 1 method calling some superclass methods\n* override of some superclass methods in subclasses\n\n## License\n\n[BSD 3-Clause License](https://opensource.org/licenses/BSD-3-Clause), see `LICENSE` in repository.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcodecop%2Fbook-discounts-refactoring-kata","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcodecop%2Fbook-discounts-refactoring-kata","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcodecop%2Fbook-discounts-refactoring-kata/lists"}