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.)

没有正确的解决方案

许可以下: CC-BY-SA归因
scroll top