Categories
python

Python Design Patterns

There is an intersting talk about Python design patterns at http://www.youtube.com/watch?v=4KZx8bATBFs&feature=related from Google Students. I really liked the comment that “Design Patterns must be studied in the context on the language in which they’ll get implemented” as some patterns can be change or disappear entirely if there is a better way to do something that the language supports.

One of the interesting talks on everybody’s favorite/hated pattern is how to deal with a singleton. Singleton’s are conceptually good (just one of something) but in practice they so often become just global variables as noted here http://c2.com/cgi/wiki?GlobalVariablesAreBad I personally prefer using dependency injection whenever appropriate, as it gives a lot more flexibility in what class the objects are actually interacting with. However with python there is an intersting approach in using the module as a singleton. This has its own issues (no subclassing modules, etc.) but does provide an interesting approach to think about (especially with the lack of private methods/members in python).

Good luck,
Michael Hubbard
https://michaelhubbard.ca

Leave a Reply

Your email address will not be published.