Closed ledjon-behluli closed 3 years ago
Hi @ledjon-behluli
Unfortunately, it is not a good example :) But thanks to that I noticed that there is no good example of Strategy Pattern in this project at all.
So I quickly created it, please check it https://github.com/kgrzybek/modular-monolith-with-ddd/tree/master/src/Modules/Payments/Domain/PriceListItems/PricingStrategies
What do you think?
Hi @ledjon-behluli
Unfortunately, it is not a good example :) But thanks to that I noticed that there is no good example of Strategy Pattern in this project at all.
So I quickly created it, please check it https://github.com/kgrzybek/modular-monolith-with-ddd/tree/master/src/Modules/Payments/Domain/PriceListItems/PricingStrategies
What do you think?
Yes I do agree! It is a better example. Though I have to say that PriceListFactory
does blurry the line a little bit, but I can see it's benefits:
It is common to use Factory Pattern with Strategy Pattern because always some object must take the responsibility to select a particular strategy. In other words, this is the place where "if's" are allowed :). I like to do it in a separate object because it can be unit tested (not shown in the project now).
By the way - great explanation, I like the comparison - generic and concrete example, well done.
@kgrzybek please have a look at the example on this one, I am not 100% sure that this is the best example to reflect the Strategy Pattern.
Thx.