Popular recipes by Ilya Pashchenko http://code.activestate.com/recipes/users/4185152/2013-02-04T21:12:27-08:00ActiveState Code RecipesObserver Pattern (Python)
2013-02-04T20:55:10-08:00Ilya Pashchenkohttp://code.activestate.com/recipes/users/4185152/http://code.activestate.com/recipes/578449-observer-pattern/
<p style="color: grey">
Python
recipe 578449
by <a href="/recipes/users/4185152/">Ilya Pashchenko</a>
(<a href="/recipes/tags/oop/">oop</a>).
</p>
<p>This is a Python implementation of the observer pattern described by Gamma et. al. It defines a one-to many dependency between objects so that when one object changes state, all its dependents are notified and updated automatically.</p>
<p>The example should output:
Setting Data 1 = 10
DecimalViewer: Subject Data 1 has data 10
HexViewer: Subject Data 1 has data 0xa
Setting Data 2 = 15
HexViewer: Subject Data 2 has data 0xf
DecimalViewer: Subject Data 2 has data 15
Setting Data 1 = 3
DecimalViewer: Subject Data 1 has data 3
HexViewer: Subject Data 1 has data 0x3
Setting Data 2 = 5
HexViewer: Subject Data 2 has data 0x5
DecimalViewer: Subject Data 2 has data 5
Detach HexViewer from data1 and data2.
Setting Data 1 = 10
DecimalViewer: Subject Data 1 has data 10
Setting Data 2 = 15
DecimalViewer: Subject Data 2 has data 15</p>
Factory pattern (Python)
2013-02-04T21:12:27-08:00Ilya Pashchenkohttp://code.activestate.com/recipes/users/4185152/http://code.activestate.com/recipes/578450-factory-pattern/
<p style="color: grey">
Python
recipe 578450
by <a href="/recipes/users/4185152/">Ilya Pashchenko</a>
(<a href="/recipes/tags/oop/">oop</a>).
</p>
<p>In the factory pattern you have an object that creates other objects.</p>