What is the difference between Factory and Strategy patterns?

前端 未结 12 1501
执念已碎
执念已碎 2020-12-02 04:53

Can any one explain the difference between factory and strategy patterns?

For me both are looking same other than an extra factory class (which create an object of

12条回答
  •  日久生厌
    2020-12-02 05:16

    The strategy pattern allows you to polymorphically change behavior of a class.

    The factory pattern allows you to encapsulate object creation.

    Gary makes a great point. If you are using the principle of coding to abstractions rather than "concretions" then a lot of the patterns start looking like variations on a theme.

提交回复
热议问题