Home > other >  The application of factory method pattern and strategy pattern scenario what is the difference
The application of factory method pattern and strategy pattern scenario what is the difference

Time:12-03

Say so many places is
Their use is not the same, the factory model is created, its role is to create the object, the strategy pattern is a behavior model, is used in the act of many choose a behaviour, focuses on the behavior of diversity,

But if for a practical application scenario, how can I tell what difference between creation and behavior... See examples of online often vague, like always feeling both can replace %...

CodePudding user response:

Factory pattern is to create the model of the design pattern provides a create objects hidden at the same time create a logical way, instead of using the new operator to instantiate objects directly, which makes the program in the judgment, for a given instance which objects need to create a more flexible, [purpose is to create an object]
The strategy pattern is a model of behavior, attention is the communication between objects, [the purpose is to choose different strategies under different behavior state]
Reference:
https://www.runoob.com/design-pattern/factory-pattern.html
https://www.runoob.com/design-pattern/strategy-pattern.html
  • Related