here we have three strategieseach using pil to perform their task individual strategies have make_background method that accepts the same set of parameters once selectedthe appropriate strategy can be called to create correctly sized version of the desktop image tiledstrategy loops over the number of input images that would fit in the width and height of the image and copies it into each locationrepeatedly centeredstrategy figures out how much space needs to be left on the four edges of the image to center it scaledstrategy forces the image to the output size (ignoring aspect ratioconsider how switching between these options would be implemented without the strategy pattern we' need to put all the code inside one great big method and use an awkward if statement to select the expected one every time we wanted to add new strategywe' have to make the method even more ungainly strategy in python the preceding canonical implementation of the strategy patternwhile very common in most object-oriented librariesis rarely seen in python programming these classes each represent objects that do nothing but provide single function we could just as easily call that function __call__ and make the object callable directly since there is no other data associated with the objectwe need do no more than create set of top-level functions and pass them around as our strategies instead opponents of design pattern philosophy will therefore say"because python has first-class functionsthe strategy pattern is unnecessaryin truthpython' first-class functions allow us to implement the strategy pattern in more straightforward way knowing the pattern exists can still help us choose correct design for our programbut implement it using more readable syntax the strategy patternor top-level function implementation of itshould be used when we need to allow client code or the end user to select from multiple implementations of the same interface the state pattern the state pattern is structurally similar to the strategy patternbut its intent and purpose are very different the goal of the state pattern is to represent state-transition systemssystems where it is obvious that an object can be in specific stateand that certain activities may drive it to different state to make this workwe need manageror context class that provides an interface for switching states internallythis class contains pointer to the current stateeach state knows what other states it is allowed to be in and will transition to those states depending on actions invoked upon it