command pattern command or the invoker to be clearthe command object does not execute anythingit is just container by implementing this patternwe have added layer of abstraction between the action to be executed and the object that invokes that action the added abstraction leads to better interaction between different objects in the systemand looser coupling between themmaking the system easier to maintain and update the heart of this design pattern is the translation of method calls into data that can be saved in variablepassed to method or function as parameterand returned from function as result the result of applying this pattern is that functions or methods become first-class citizens when functions are first class citizens variables can point to functionsfunctions can be passed as parameter to other functionsand they can be returned as the result from executing function what is interesting about the command patternspecifically this ability to turn behavior into first-class citizenis that we could use this pattern to implement functional programming style with lazy evaluationmeaning that functions could be passed to other functions and could be returned by functions all functions get passed all that is needed for executionwith no global stateand functions are only executed when an actual result needs to be returned this is fairly shallow description of functional programmingbut the implications are deep the interesting twist in our tale is that in python everything is functionand as such we could also do away with the class that encapsulates the function call and just pass the function with the relevant parameters to the invoker def text_writer(string string )print("writing {{}format(string string )class invoker(object)def __init__(self)self commands [def add_command(selfcommand)self commands append(commanddef run(self)for command in self commandscommand["function"](*command["params"]