Most viewed recipes tagged "design_pattern" Code RecipesThread Pool (Python) 2008-11-30T05:42:59-08:00Louis RIVIERE <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> Design Pattern -- Inherit from an instance (Python) 2010-02-22T06:04:16-08:00Daniel Cohn <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> Design by contract on python vanilla (Python) 2013-11-05T20:50:30-08:00Alan Cristhian Ruiz <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> Yet another Null object (Python) 2008-11-11T15:24:20-08:00George Sakkis <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="">null</a> or <a href="">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> Multiple unique class instances - a tentative design pattern (Python) 2013-02-23T14:11:44-08:00Moritz Beber <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="">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>