What is the difference between Factory and Strategy patterns?

前端 未结 12 1485
执念已碎
执念已碎 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:21

    Factory pattern is a creational pattern, which is created with specified properties(behaviour). while at run time after creation u cn't change it's properties(behaviour). so if u need different properties(behaviour) u have to delete the object and create new object with needed properties(behaviour). which is not gud. while in case of strategy pattern u can change the properties(behaviour) at run time.

提交回复
热议问题