I'm reading the awesome Head First Design Patterns book. As an exercise I converted first example (or rather a subset of it) to Python. The code I got is rather too simple, i.e. there is no abstract nor interface declarations, it's all just 'classes'. Is that the right way to do it in Python? My code is below, original Java code and problem statement can be found at http://books.google.com/books?id=LjJcCnNf92kC&pg=PA18class QuackBehavior():    def __init__(self):        pass    def quack(self):        passclass Quack(QuackBehavior):    def quack(self):        print Quack!class QuackNot(QuackBehavior):    def quack(self):        print ...class Squeack(QuackBehavior):    def quack(self):        print Squeack!class FlyBehavior():    def fly(self):        passclass Fly():    def fly(self):        print I'm flying!class FlyNot():    def fly(self):        print Can't fly...class Duck():    def display(self):        print this.name    def performQuack(self):        self.quackBehavior.quack()    def performFly(self):        self.flyBehavior.fly()class MallardDuck(Duck):    def __init__(self):        self.quackBehavior = Quack()        self.flyBehavior = Fly()if __name__ == __main__:    mallard = MallardDuck()    mallard.performQuack()    mallard.performFly()    mallard.flyBehavior = FlyNot()    mallard.performFly()
Strategy Design Pattern in Python
python;object oriented;design patterns
In Python, you can pass functions as argument.  This simplifies the Strategy Design pattern, as you don't need to create classes just for one method or behavior.  See this question for more info.def quack():    print Quack!def quack_not():    print ...def squeack():    print Squeack!def fly():    print I'm flying!def fly_not():    print Can't fly...class Duck:    def display(self):        print this.name    def __init__(self, quack_behavior, fly_behavior):        self.performQuack = quack_behavior        self.performFly = fly_behaviorclass MallardDuck(Duck):    def __init__(self):        Duck.__init__(self, quack, fly)if __name__ == __main__:    duck = Duck(quack_not, fly_not)    duck.performQuack()    mallard = MallardDuck()    mallard.performQuack()    mallard.performFly()    mallard.performFly = fly_not    mallard.performFly()Output:...Quack!I'm flying!Can't fly...