strategy-pattern

Dependency Injection and the Strategy Pattern

大憨熊 提交于 2019-11-26 16:08:16
问题 There is an enormous amount of discussion on this topic, but everyone seems to miss an obvious answer. I'd like help vetting this "obvious" IOC container solution. The various conversations assume run-time selection of strategies and the use of an IOC container. I will continue with these assumptions. I also want to add the assumption that it is not a single strategy that must be selected. Rather, I might need to retrieve an object-graph that has several strategies found throughout the nodes

What is the difference between Factory and Strategy patterns?

試著忘記壹切 提交于 2019-11-26 15:05:20
问题 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 product in factory patterns) 回答1: A factory pattern is a creational pattern. A strategy pattern is an operational pattern. Put another way, a factory pattern is used to create objects of a specific type. A strategy pattern is use to perform an operation (or set of operations) in a particular manner. In the classic example, a

How does the Strategy Pattern work? [closed]

你。 提交于 2019-11-26 07:22:04
问题 Closed . This question needs to be more focused. It is not currently accepting answers. Want to improve this question? Update the question so it focuses on one problem only by editing this post. Closed 5 years ago . How does it work, what is it used for and when should one use it? 回答1: Let's explain the strategy pattern the easy way: You have a class Car() with a method run() , so you use it this way in a pseudo language: mycar = new Car() mycar.run() Now, you may want to change the run()

Real World Example of the Strategy Pattern

时光毁灭记忆、已成空白 提交于 2019-11-25 23:48:57
问题 I\'ve been reading about the OCP principal and how to use the strategy pattern to accomplish this. I was going to try and explain this to a couple of people, but the only example I can think of is using different validation classes based on what status an \"order\" is. I\'ve read a couple of articles online, but these don\'t usually describe a real like reason to use the strategy, like generating reports/bills/validation etc... Are there any real world examples where you think a strategy