Popular recipes tagged "design_pattern"http://code.activestate.com/recipes/tags/design_pattern/2013-11-05T20:50:30-08:00ActiveState Code RecipesDesign by contract on python vanilla (Python)
2013-11-05T20:50:30-08:00Alan Cristhian Ruizhttp://code.activestate.com/recipes/users/4186199/http://code.activestate.com/recipes/578767-design-by-contract-on-python-vanilla/
<p style="color: grey">
Python
recipe 578767
by <a href="/recipes/users/4186199/">Alan Cristhian Ruiz</a>
(<a href="/recipes/tags/demo/">demo</a>, <a href="/recipes/tags/design_pattern/">design_pattern</a>, <a href="/recipes/tags/productivity/">productivity</a>).
Revision 2.
</p>
<p>The code below is an example that shows that we can do design by contract in python without any non-standard module.</p>
Multiple unique class instances - a tentative design pattern (Python)
2013-02-23T14:11:44-08:00Moritz Beberhttp://code.activestate.com/recipes/users/4185350/http://code.activestate.com/recipes/578471-multiple-unique-class-instances-a-tentative-design/
<p style="color: grey">
Python
recipe 578471
by <a href="/recipes/users/4185350/">Moritz Beber</a>
(<a href="/recipes/tags/design_pattern/">design_pattern</a>, <a href="/recipes/tags/pattern/">pattern</a>, <a href="/recipes/tags/unique/">unique</a>).
</p>
<p>Coming from Bioinformatics and having to deal with multiple objects with unique properties, like genes, proteins, and many more, I felt the need for a class that would always yield a unique instance based on a chosen identifier. This is because I always wanted the same instances whose attributes were filled with information and track them in various storage classes, like dictionaries, lists, etc. The code for the class lives <a href="https://github.com/Midnighter/unique-base">over on github</a>. Recently, I've added a lot of parallel-processing code so I adapted the pickling behaviour for this class to also yield existing instances. What follows is an example of how to use it and some discussion questions.</p>
Design Pattern -- Inherit from an instance (Python)
2010-02-22T06:04:16-08:00Daniel Cohnhttp://code.activestate.com/recipes/users/4172918/http://code.activestate.com/recipes/577026-design-pattern-inherit-from-an-instance/
<p style="color: grey">
Python
recipe 577026
by <a href="/recipes/users/4172918/">Daniel Cohn</a>
(<a href="/recipes/tags/design_pattern/">design_pattern</a>, <a href="/recipes/tags/factory_class/">factory_class</a>, <a href="/recipes/tags/inheritance/">inheritance</a>, <a href="/recipes/tags/instance/">instance</a>).
Revision 4.
</p>
<p>Take an instance (call it foo) and create a factory class (call it InstanceFactory) that produces foo's. Then inherit from InstanceFactory.</p>
Thread Pool (Python)
2008-11-30T05:42:59-08:00Louis RIVIEREhttp://code.activestate.com/recipes/users/4035877/http://code.activestate.com/recipes/576576-thread-pool/
<p style="color: grey">
Python
recipe 576576
by <a href="/recipes/users/4035877/">Louis RIVIERE</a>
(<a href="/recipes/tags/design_pattern/">design_pattern</a>, <a href="/recipes/tags/pool/">pool</a>, <a href="/recipes/tags/threads/">threads</a>, <a href="/recipes/tags/thread_pool/">thread_pool</a>).
Revision 4.
</p>
<p>Easy to use Thread Pool with a dynamically adjustable pool size.</p>
Yet another Null object (Python)
2008-11-11T15:24:20-08:00George Sakkishttp://code.activestate.com/recipes/users/2591466/http://code.activestate.com/recipes/576562-yet-another-null-object/
<p style="color: grey">
Python
recipe 576562
by <a href="/recipes/users/2591466/">George Sakkis</a>
(<a href="/recipes/tags/design_pattern/">design_pattern</a>, <a href="/recipes/tags/dummy/">dummy</a>, <a href="/recipes/tags/null/">null</a>).
</p>
<p>This recipe builds on two previously posted recipes for a <a href="http://code.activestate.com/recipes/68205/">null</a> or <a href="http://code.activestate.com/recipes/576447/">dummy</a> object by modifying a few methods (e.g. as in SQL, <code>Null == Null</code> is Null, not True), supporting most (all?) special methods (e.g. int(Null)) and providing correct pickling/unpickling.</p>