I start learning Design Patterns. Now I understand a little bit but there are quite a lot of confusions for me. What\'s the difference between Strategy DP and <
Strategies incapsulate different behaviors behind the same interface. You instantiate Strategies with new
operator. For example (the same business case as Frederik suggested):
DiscountCalculator calc = new GoogCustomerDiscountCalculator();
Integer discount = calc.calculate();
Factory Method incapsulates instantiation mechanism of some other interface (maybe a Strategy, but maybe something else). For example:
DiscountFactory factory = new DiscountFactory();
DiscountCalculator calc = factory.getDiscountCalculator();
Integer discount = calc.calculate();
Strategy pattern is often used together with Factory Method, while Factory Method is often used for instantiation of other stereotypes, not only Strategies.