Popular recipes by Moritz Beber http://code.activestate.com/recipes/users/4185350/2013-02-23T14:11:44-08:00ActiveState Code RecipesMultiple 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>