Popular Python recipes tagged "abstract_base_class"http://code.activestate.com/recipes/langs/python/tags/abstract_base_class/2015-10-15T21:33:32-07:00ActiveState Code Recipesdefdict (Python) 2015-10-15T15:45:16-07:00userhttp://code.activestate.com/recipes/users/4187240/http://code.activestate.com/recipes/579113-defdict/ <p style="color: grey"> Python recipe 579113 by <a href="/recipes/users/4187240/">user</a> (<a href="/recipes/tags/abstract_base_class/">abstract_base_class</a>, <a href="/recipes/tags/datastructures/">datastructures</a>, <a href="/recipes/tags/dictionary/">dictionary</a>). </p> <p>default dictionary with collision function to handle key collisions.</p> graph (Python) 2015-10-15T21:33:32-07:00userhttp://code.activestate.com/recipes/users/4187240/http://code.activestate.com/recipes/578615-graph/ <p style="color: grey"> Python recipe 578615 by <a href="/recipes/users/4187240/">user</a> (<a href="/recipes/tags/abstract_base_class/">abstract_base_class</a>, <a href="/recipes/tags/datastructures/">datastructures</a>, <a href="/recipes/tags/graph/">graph</a>). Revision 4. </p> <p>Abstract Graph Class: A Graph is a very abstract and powerful data structure to hold many different kinds of data relationships. </p> Sets with a custom equality/uniqueness function (Python) 2009-10-29T21:08:22-07:00Gabriel Genellinahttp://code.activestate.com/recipes/users/924636/http://code.activestate.com/recipes/576932-sets-with-a-custom-equalityuniqueness-function/ <p style="color: grey"> Python recipe 576932 by <a href="/recipes/users/924636/">Gabriel Genellina</a> (<a href="/recipes/tags/abstract_base_class/">abstract_base_class</a>, <a href="/recipes/tags/mutableset/">mutableset</a>, <a href="/recipes/tags/set/">set</a>, <a href="/recipes/tags/unique/">unique</a>). Revision 4. </p> <p>The builtin <code>set</code> and <code>frozenset</code> types are based on object equality; they call __eq__ to determine whether an object is a member of the set or not. But there are cases when one needs a set of objects that are compared by other means, apart from the default __eq__ function. There are several ways to achieve that; this recipe presents two classes, FrozenKeyedSet and KeyedSet, that take an additional function <code>key</code> which is used to determine membership and uniqueness. Given two objects which return the same value for <code>key</code>, only one of them will be in the set.</p> Component architecture through data descriptors and function decorators (Python) 2009-07-23T11:13:48-07:00Danny Ghttp://code.activestate.com/recipes/users/4164396/http://code.activestate.com/recipes/576852-component-architecture-through-data-descriptors-an/ <p style="color: grey"> Python recipe 576852 by <a href="/recipes/users/4164396/">Danny G</a> (<a href="/recipes/tags/abc/">abc</a>, <a href="/recipes/tags/abstract_base_class/">abstract_base_class</a>, <a href="/recipes/tags/component/">component</a>, <a href="/recipes/tags/interface/">interface</a>, <a href="/recipes/tags/plugin/">plugin</a>). Revision 5. </p> <p>My desire was to design a class with defined attributes that when assigned on instances, would expand the instance's functionality. In other words if I create an instance of class A, then assign a 'component' attribute upon that instance, I should be able to call methods of the component object through the original instance. I believe this is somewhat similar to interfaces and abstract base classes (and I read up on both a bit), but I want to rely more on introspection of the object to see what it can do versus confining it to a set interface.</p> Components and Abilities (different implementation of Component architecture) (Python) 2009-07-23T13:26:32-07:00Danny Ghttp://code.activestate.com/recipes/users/4164396/http://code.activestate.com/recipes/576854-components-and-abilities-different-implementation-/ <p style="color: grey"> Python recipe 576854 by <a href="/recipes/users/4164396/">Danny G</a> (<a href="/recipes/tags/abc/">abc</a>, <a href="/recipes/tags/ability/">ability</a>, <a href="/recipes/tags/abstract_base_class/">abstract_base_class</a>, <a href="/recipes/tags/component/">component</a>, <a href="/recipes/tags/descriptor/">descriptor</a>, <a href="/recipes/tags/dynamic/">dynamic</a>, <a href="/recipes/tags/interface/">interface</a>, <a href="/recipes/tags/plugin/">plugin</a>). Revision 6. </p> <p>I define a 'Component' as an attribute (typing optional) that instances can assign objects to. Nothing special there, but their usefulness comes in with 'Abilities'. If a class inherits from 'ClassWithAbilities', it will be given a special attribute 'abilities' that will grow/shrink when other classes with abilities are assigned to an instances attributes. It increases/decreases the functionality of the instance depending on what objects are assigned to it. All of these abilities are accessed through the 'abilities' attribute. This is a redesign of <a href="http://code.activestate.com/recipes/576852/"><a href="http://code.activestate.com/recipes/576852/">Recipe 576852</a></a>, but I believe is different enough to warrant a new recipe.</p>