I am now on Twitter! Meet me on Twitter here (my nick is pkrumins.)
Or on Google Buzz and Facebook.

In my previous post about learning Python programming through video lectures I stopped at three lectures on Design Patterns. This time I continue from there.
If you don’t know what a Design Pattern is, think of it as a simple solution to a specific problem that occurs very frequently in software design.
For example, suppose you use a bunch of unrelated pieces of code. It is a nice idea to bring the unrelated pieces of code together in a unified interface. This design pattern is called Facade. There are a bunch of patterns like this one!
The three lectures are given by Alex Martelli who works as “Über Tech Lead” for Google.
Python Design Patterns, Part I
Alex briefly covers the history and main principles of Design Patterns and quickly moves to discussing Structural and Behavioral DPs in Python.
Interesting ideas from the lecture:
- [03:24] The name “Design Patterns” was first used by Christopher Alexander, an architect, who abstracted the idea of building buildings as building them using well known patterns which can be applied to the same problem over and over again without ever doing it the same way twice.
- [05:30] Design Patterns are mostly applied to Object Oriented programming because it’s the most widely spread programming paradigm nowadays.
- [08:36] Design Patterns are not invented, they are discovered.
- [10:00] Alex says that the original book Design Patterns
by the Gang of Four should be read only when you are a master of DPs.
- [13:10] Three classical categories of DPs are - Creational (deal with object instantiaton), Structural (deal with composition of objects) and Behavioral (deal with interaction of objects).
- [14:05] “Program to an interface, not to an implementation.”
- [17:00] Use inheritance only when absolutely necessary, otherwise use “hold or wrap” principle.
- [18:30] Never have more than one dot - Law of Demeter.
- [18:50] Inheritance cannot restrict, use wrapping to restrict.
- [21:41] In most of the cases when you need a single instance of something in Python, use a module instead of a class.
- [22:23] Otherwise, just make 1 instance (without enforcing one).
- [22:59] Singleton is also called “Highlander”.
- [24:50] There is basically no way to support subclassing well in Singleton.
- [25:45] Monostate is also called “Borg”.
- [27:00] Python’s data overriding helps in Monostate Design Pattern.
- [29:00] Each Python’s type/class is essentially a factory.
- [32:06] Python does a “two-phase object construction”.
- [35:30] Adapter Design Pattern (it tweaks the interface to your needs).
- [41:22] Facade Design Pattern (it provides a simple subset of a complex functionality).
- [47:25] Bridge Design Pattern (it abstracts interface from the implementation).
- [49:30] Decorator Design Pattern (it transparently modifies some functionality.).
- [50:24] Proxy Design Pattern (sounds the same as decorator just for access control).
- [51:21] Q and A!
Python Design Patterns, Part II
In this lecture Alex discusses behavioral patterns. Unlike the first part, he goes in depth of some of the patterns and explains how they can be implemented in Python.
Interesting ideas from the lecture:
- [02:25] Template Method is a great pattern with a lousy name, a better name is “self-delegation”.
- [03:43] Example of Template Method Design Pattern (text pagination).
- [08:50] Template Method Rationale.
- [09:45] The “Hollywood Principle” - “don’t call us, we’ll call you”
- [12:05] In Python you can also override data.
- [13:10] Example of Template Method in Queue.Queue.
- [14:05] If you are a good Python programmer, use Queue in threaded applications.
- [17:45] Customizing Queue.
- [19:30] Example of Template Method in cmd.Cmd.cmdloop.
- [21:22] Example of Template Method in asyncore.dispatcher.
- [22:30] Variant of Template Method - Mixin (not presented in Gang of Four book
). It’s a class to be multiply-inherited from and supplies organizing methods only.
- [25:50] Template Method in DictMixin class.
- [26:45] Example of DictMixin usage.
- [29:00] Hooks can be factored out in another class. Two examples of this from Python’s stdlib are HTML’s formatter vs. writer, SAX’s parser vs. handler
- [32:40] Hook method introspection example of cmd.Cmd.docmd.
- [33:30] There are three kinds of Template Methods - plain, factored into separate classes, and introspective.
- [34:35] Example of all three kinds of Template Methods used in unittest.TestCase.
- [36:17] State and Strategy Design Patterns. Very similar classes in what they do. They both factor out object’s behavior.
- [40:40] Ring buffer example done via State Design Pattern.
- [43:35] Q and A!
Python Design Patterns, A Recap
This video lecture was presented at Google Developers day. It is a short version of the previous two video lectures. It starts with an example of Facade Design Pattern, moves on to history and all the types of design patterns.
I did not write out the interesting moments from this lecture as it was a subset of previous two lectures.
If you liked these lectures, check out this geek song about another commonly used design pattern - Model-View-Controller Song :)
Even though these were Python design patterns, to understand some of them I used Perl Design Patterns website!
Were there any interesting points in the lectures that caught your attention?
Did you like this post? Subscribe here:
If you really enjoyed the post, I'd appreciate a gift from my geeky Amazon book wishlist. Books would make me more educated and I could write even better posts. Thanks! :)

(6 votes, average: 4.67 out of 5)
|
|
|


April 24th, 2008 at 8:58 am
Videos are great and all, but using Python is the best way to learn :)
April 25th, 2008 at 7:58 am
[…] Learning Python Design Patterns Through Video Lectures - good coders code, great reuse (tags: programming toread video python) […]
June 17th, 2008 at 3:31 pm
[…] read more | digg story […]
July 27th, 2008 at 6:33 am
[…] This is the third post in an article series about Python video lectures. The previous two posts covered learning basics of Python and learning Python design patterns. […]
November 23rd, 2008 at 3:43 am
I already very much am interested for a long time in a python. Thanks
December 20th, 2008 at 10:07 pm
Hello. I think you are eactly thinking like Sukrat. I really loved the post.
April 29th, 2009 at 8:52 pm
Hi Peteris, you have a very nice website, I really enjoy reading your posts!
There’s another interesting thing Alex points out in the first lecture: use no more than one dot in variable names.
May 16th, 2009 at 5:42 pm
[…] [upmod] [downmod] Learning Python Design Patterns Through Video Lectures - good coders code, great reuse (www.catonmat.net) 1 points posted 1 year ago by SixSixSix tags imported python saved by 1 […]