Check the following method:
public void doStuff(NoYes condition = NoYes::Yes)
{
if (condition == NoYes::Yes)
{
doEvenMoreStuff();
}
}
Add Chain of Command method to the previous class:
void doStuff(NoYes condition)
{
doChainOfCommandStuff();
next doStuff();
}
"Condition" variable could be skipped because it is optional in the original method.
Now each time before original doStuff() method is called, our Chain of Command method will be executed. It omits "condition" variable, so it will be set to default NoYes:Yes each time original method is executed. As a result - "if" condition will always be True and doEvenMoreStuff() method will always be called.
Lesson learned: always pass all, even optional, method parameters when using Chain of Command.
No comments:
Post a Comment