strategy pattern def main()no_strategy strategyexecutor(addition_strategy strategyexecutor(additionstrategy()subtraction_strategy strategyexecutor(subtractionstrategy()no_strategy execute( addition_strategy execute( subtraction_strategy execute( if __name__ ="__main__"main(this again results in the required outputstrategy not implemented - at least we dealt with the sprawling if statement as well as the need to update the executor function every time we add another strategy this is good step in the right direction our system is little more decoupledand each part of the program only deals with the part of the execution it is concerned with without its worrying about the other elements in the system in the traditional implementationwe made use of duck typingas we have done many times in this book nowwe will use another powerful python tool for writing clean code--using functions as if they were any other value this means we can pass function to the executor class without first wrapping the function in class of its own this will not only greatly reduce the amount of code we have to write in the long runbut it will also make our code easier to read and easier to test since we can pass arguments to the functions and assert that they return the value we expect class strategyexecutor(object)def __init__(selffunc=none)if func is not noneself execute func def execute(self*args)print("strategy not implemented "