Is it OK to pass the concrete client to a method on the concrete strategy?
https://softwareengineering.stackexchange.com/questions/124616
-
03-11-2019 - |
Question
When using the strategy pattern, is it good practice to pass this
to a method on this.strategy
?
I have a strategy interface with one call, TakeAction
. The idea is that TakeAction decides which of the several possible actions the Client should perform and then calls the appropriate method on the client. So in a concrete strategy, the TakeAction
method might look like:
void TakeAction(IAbstractClient client)
{
if (client.IsBlah()) client.UnBlah(this.BlahValue1, this.BlahValue2);
else if (client.CanFoo()) client.Foo(this.FooValue);
else if (this.ShouldTwiddle()) client.Twiddle();
}
And in the client, the call looks like:
this.strategy.TakeAction(this);
Is this good form? Or is there a better way to do this? (Passing back a class with an enum describing the action and the values to pass to it seemed overkill.)
No correct solution
Licensed under: CC-BY-SA with attribution
Not affiliated with softwareengineering.stackexchange