Sunday, 15 June 2014

oop - Design pattern advice for calculating prices -



oop - Design pattern advice for calculating prices -

i have best practive / design pattern question. i'm working on dispatching scheme need calculate price.

in settings of scheme admin can manage 8 different rate rules. there 1 minimum fee, parking, toll, ... .

every rule can activated , deactivated, , every rule has own parameters, illustration rule 'parking' has parameters 'price', 'vat', 'price per hr or fixed price', ...

i thinking of using strategy pattern or bridge pattern, neither both fit think.

an other solution simple inheritance without using interface.

i have modeled something, i'm not 100% pleased result:

https://www.dropbox.com/s/jllb8h0671ssq8u/raterule-pattern.png

sounds reasonable me... whatever pattern phone call it, see lot of sense in thought - collection of parkingcalculator, tollcalculator etc, mutual interface. makes easy add together more types of payments if pop along way, , allows replace pieces (e.g. different parking policies). if latter occurs, indeed falls classical definition of "strategy".

personally i'd hide behind higher-level interface of "calculatetotal" - current implementation beingness "iterate through collection of calculators", rest of scheme shouldn't mind if changes (e.g. if rules become complex require tree, or rest phone call external service ministry of transportation).

oop design-patterns uml

No comments:

Post a Comment