strategy-pattern

What is the exact definition of the strategy design pattern?

戏子无情 提交于 2019-12-21 04:39:19
问题 I had a geek fight with someone over what the strategy pattern really is and I need a expert to settle the matter. We both agree that the strategy pattern allows for the guts of a class (e.g., the behavior) to be swapped out at runtime while maintaining the same interface. However, her contention is that "For [the algorithms] to be a strategy, You would have to get the same results". My contention is that swapping an "algorithm" or logic of a class could mean that the results of the

Strategy Pattern V/S Decorator Pattern

假装没事ソ 提交于 2019-12-20 07:59:12
问题 I just came across two patterns. Strategy Pattern Decorator Strategy Pattern :- Strategy pattern gives several algorithms that can be used to perform particular operation or task. Decorator Pattern :- Decorator pattern adds some functionality to component. In fact I have found that Strategy Pattern and Decorator Pattern can also be used interchangeably. Here is the link :- When and How Strategy pattern can be applied instead of decorator pattern? What is the difference between Strategy

Is 'Strategy Design Pattern' no more than the basic use of polymorphism?

守給你的承諾、 提交于 2019-12-19 19:45:04
问题 In Strategy Design Pattern , what we do is Create a common interface. Implement a set of classes using that interface with overridden method(s). Let the run time to choose the actual class for an object which has the same type with that common interface and call the overridden method(s) which will resolve correctly according to the class. My question is, Isn't it the basic example of polymorphism and method overriding we learn? other than the possibility of using an abstract class too,

Can't call static method from class as variable name?

我的未来我决定 提交于 2019-12-19 06:14:27
问题 I'm using php 5.2.6. I have a strategy pattern, and the strategies have a static method. In the class that actually implements one of the strategies, it gets the name of the strategy class to instantiate. However, I wanted to call one of the static methods before instantiation, like this: $strNameOfStrategyClass::staticMethod(); but it gives T_PAAMAYIM_NEKUDOTAYIM . $> cat test.php <? interface strategyInterface { public function execute(); public function getLog(); public static function

In the strategy pattern can the strategy take the Context as parameter

梦想与她 提交于 2019-12-18 15:16:12
问题 Feedback summary I will now close this thead (I think there will be no more feedback) and try to summarize what I understood using the "Context" as a parameter for my strategy introduces a tight coupling that should be avoided and also could force me to expose properties that should perhaps remain hidden in the class. To minimize coupling, it would be better to provide the needed values or at least to use an interface instead of a concrete type to the strategy. I'm trying to get a clear

Difference between Strategy pattern and Delegation pattern

ぃ、小莉子 提交于 2019-12-18 11:29:36
问题 What is the difference between Strategy pattern and Delegation pattern (not delegates)? 回答1: the strategy pattern is a very specific design solution to a common software problem. the strategy pattern implies that there will be an interface called Strategy (or with Strategy as part of the name). this interface should have a method called execute(). one or more concrete classes called something like ConcreteStrategyA, ConcreteStrategyB, etc. that implement the Strategy interface. there should

Strategy Pattern and Dependency Injection using Unity

对着背影说爱祢 提交于 2019-12-17 15:36:25
问题 I am finally getting my feet wet with Dependency Injection (long overdue); I got started playing with Unity and run into an issue with the strategy pattern. I can use the container to return to me specific implementations of a strategy based on a name, but what I don't see is how I am supposed to get the right strategy in the context. Let's illustrate on a simple example: the context is a car, which has an IEngine (the strategy), with 2 implementations, FastEngine and SlowEngine. The code

What is the difference between Strategy pattern and Dependency Injection?

别说谁变了你拦得住时间么 提交于 2019-12-17 15:05:02
问题 Strategy pattern and Dependency Injection both allow us to set / inject objects at run time. What is the difference between Strategy pattern and Dependency Injection? 回答1: DI and Strategy work in the same way, but Strategy is used for more fine-grained and short-lived dependencies. When an object is configured with a "fixed" Strategy, for example when the object is constructed, the distinction between Strategy and DI blurs. But in a DI scenario it is more unusual that the dependencies of

Asp.Net MVC and Strategy pattern

时光毁灭记忆、已成空白 提交于 2019-12-13 22:04:16
问题 I have an MVC application that uses Entity Framework. I am using a repository, unit of work and unity as dependency injection. The problem I have is that I have different authentication types, and each type I want a different class, so I decided to use the Strategy pattern public interface IAuthStrategy { OperationResponse<AuthenticationMechanismDTO> GetAuthenticationMechanism(string userName); } public class AuthStrategy { readonly IAuthStrategy _authStrategy; public AuthStrategy

Strategy pattern or function pointer [closed]

五迷三道 提交于 2019-12-13 19:29:54
问题 Closed . This question needs details or clarity. It is not currently accepting answers. Want to improve this question? Add details and clarify the problem by editing this post. Closed 4 years ago . In C++ when I have algorithm which could accept different behaviour in runtime I rather use function pointer. For example, a program for drawing charts has one algorithm to draw line which can accept any function to specialize shape of this line. In Java there are no function pointers and I am