1 """ DecoratorPattern example
   2 """
   3 
   4 class Letter:
   5     def draw(self):
   6         raise NotImplementedError
   7     def send(self):
   8         print "we are sending it..."
   9 
  10 class LetterPrinter(Letter):
  11     def __init__(self, aName):
  12         self.name = aName
  13     def draw(self):
  14         print "Dear Mr. %s"%self.name
  15         print "Thank you"
  16         print
  17         print "Sincerely Yours, John"
  18 
  19 class BorderDecorator(Letter):
  20     def __init__(self, aDecoratee, width=20):
  21         self._decoratee = aDecoratee
  22         self._width = width
  23     def draw(self):
  24         print "="*self._width
  25         self._decoratee.draw()
  26         print "="*self._width
  27 
  28 lforHenry = LetterPrinter('Henry')
  29 lforHenry.draw()
  30 lforHenry.send()
  31 
  32 blforHenry = BorderDecorator(lforHenry)
  33 blforHenry.draw()
  34 blforHenry.send()
web biohackers.net