the user code connecting to the strategy pattern simply needs to know that it is dealing with the abstraction interface the actual implementation chosen performs the same taskbut in different wayseither waythe interface is identical strategy example the canonical example of the strategy pattern is sort routinesover the yearsnumerous algorithms have been invented for sorting collection of objectsquick sortmerge sortand heap sort are all fast sort algorithms with different featureseach useful in its own rightdepending on the size and type of inputshow out of order they areand the requirements of the system if we have client code that needs to sort collectionwe could pass it to an object with sort(method this object may be quicksorter or mergesorter objectbut the result will be the same in either casea sorted list the strategy used to do the sorting is abstracted from the calling codemaking it modular and replaceable of coursein pythonwe typically just call the sorted function or list sort method and trust that it will do the sorting in near-optimal fashion sowe really need to look at better example let' consider desktop wallpaper manager when an image is displayed on desktop backgroundit can be adjusted to the screen size in different ways for exampleassuming the image is smaller than the screenit can be tiled across the screencentered on itor scaled to fit there are othermore complicatedstrategies that can be used as wellsuch as scaling to the maximum height or widthcombining it with solidsemi-transparentor gradient background coloror other manipulations while we may want to add these strategies laterlet' start with the basic ones our strategy objects takes two inputsthe image to be displayedand tuple of the width and height of the screen they each return new image the size of the screenwith the image manipulated to fit according to the given strategy you'll need to install the pillow module with pip install pillow for this example to workfrom pil import image class tiledstrategydef make_background(selfimg_filedesktop_size)in_img image open(img_fileout_img image new('rgb'desktop_sizenum_tiles