Strategy pattern in python

by , under python

Here is an example of strategy pattern in python. The alogrithm that varies in this example is the conversion of csv file to xml, html and any other formats. The client is the CsvUtil class. As you can see we can change the conversion at run time and also we can apply all the alogrithm if we wish to which we can’t achieve when we go for the regular inheritance model.  Please do note that an abstract class is equivalent to interface when there is no implementation.

Source: https://gist.github.com/rajaramanathan/0fef003196d5ccf654b7

  1. Y.Chaouche

    Strategy + Façade : here, the client class also has a convert method that is just a facade to Strategy.convert. Right ?