April 2014
Beginner to intermediate
634 pages
15h 22m
English
A class decorator creates new method functions using a two-step process: by creating the method function and then inserting it into the class definition. This is often better done via a mixin class than a decorator. The obvious and expected use of a mixin is to insert methods. Inserting methods another way is less obvious and can be astonishing.
In the example of the Total_Ordering decorator, the exact method functions inserted were flexible and depended on what was already provided. This was a kind of special case that was typical but also very clever.
We might want to define a standardized memento() method. We'd like to include this standard method function in a variety of classes. We'll look at the decorator ...