Which design pattern or combination of patterns would be correct or most suitable for the following common scenario:
Let's say I have a method which places an order. I have different order types and different countries. The method's implementation differs based on order type and also country.
My idea is to use the strategy pattern where I could have objects like OrderType1Country1Strategy, OrderType1Country2Strategy, OrderType2Country1Strategy etc.
My problem with this is that any two class can have common code which I'm not sure how best to handle. Any ideas for that or alternative patterns? Could decorator be used somehow?
You may want to take a look at the Bridge design pattern which provides a way to avoid the explosion of the number of (sub)classes.
Basically, you could separate the hierarchies of order and country classes and compose the two via bridge.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With