chain of responsibility pattern def main_function(headrequest)head execute(requestif __name__ ="__main__"hd function class(current hd current next_to_execute function class(current current next_to_execute current next_to_execute function class(current current next_to_execute current next_to_execute function class(main_function(hd" "already it is clear that we have much cleaner solution at hand we did not have to make any changes to the way each class is connected to the nextand apart from passing on the requestwe did not require any changes to be made to the individual execute functions or the main function in order to accommodate the way each class executes the request we have clearly separated each function into its own unit of code that can be plugged intoor removed fromthe chain of classes dealing with the request each handler cares only about its own execution and ignores what happens when another handler executes because of the query the handler decides in the moment if it should do anything as result of the request it receiveswhich leads to increased flexibility in determining which handlers should execute as result of query the best part of this implementation is that handlers can be added and removed at runtimeand when the order is unimportant in terms of the execution queueyou could even shuffle the order of the handlers this only goes to showonce againthat loosely coupled code is more flexible than tightly coupled code