kgrzybek / modular-monolith-with-ddd

Full Modular Monolith application with Domain-Driven Design approach.
MIT License
10.89k stars 1.71k forks source link

Added to catalog of terms: Strategy Pattern #196

Closed ledjon-behluli closed 3 years ago

ledjon-behluli commented 3 years ago

@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.

kgrzybek commented 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?

ledjon-behluli commented 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?

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:

kgrzybek commented 3 years ago

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.