In my application I have different discount services that can grow in the future by adding new type of discount, right now each decorator class instance will be created based on the DB tables that stores the offer type and percentage, so the problem is
- at run time I retrieve all offer types and percentage and based on the type I will create a **decorator object ** of the right class type
- this will be handled through conditions which will keep growing whenever I add a new type of discount class I will have to handle it with a new else if. what could be a solution for that?
I thought about this solution:
-
DiscountTypeCreator: it creates only instances of a specific decorator discount
-
OfferHandler: has a general Discount object, and will call all creators in sequence ex: Obj = creator1.createDecoration Obj = creator2.createDecorarion
-
whenever a new decoration is added, a new creator class will be created as well that handle the creation cases, and the creator will be added to the sequence of the OfferHandler.
I Don't know whether this solution follows SOLID or not, and if there might be a better and more extendable solution
Aucun commentaire:
Enregistrer un commentaire