observer design pattern

D-Man dsh8290 at rit.edu
Tue Jan 23 16:21:45 EST 2001


On Mon, Jan 22, 2001 at 04:09:48PM -0500, Roland Schlenker wrote:
| fray_fernando at my-deja.com wrote:
| > 
| > Where can I find some python sample code implementing the observer
| > pattern? O:-)
| > TIA
| > 
| > Sent via Deja.com
| > http://www.deja.com/
| 
| This is the example in the Design Patterns book for the observer
| pattern written in Python.
| 
| # Demonstrate an observer pattern.
| 
| import time
| 
| class Observer:
|     def __init__(self):
|         pass
|     def update(self, theChangedSubject):
|         pass
[snip]

Since Python is dynamically typed, this Observer class (or interface,
as it should be in Java) is unnecessary since it doesn't do anything.
It may, however, improve readability when the concrete subclass
inherits from it.  Though maybe that just belongs in a docstring or
comment.

Just some thoughts.

-D





More information about the Python-list mailing list