On 2007-02-15, Michele Simionato <[EMAIL PROTECTED]> wrote: > On Feb 13, 9:14 am, Peter Otten <[EMAIL PROTECTED]> wrote: >> "Avoid inheritance" would be almost as justified :-) > > In other words, if you are inheriting just two or three methods > it may works, but when you start having dozens of methods > inherited from different sources, your code will become to look > as spaghetti code. This is why in general I (as many people > here) suggest delegation over inheritance.
I consider inheritance in Python when I see that the class I'm implementing contains some sort of status code that controls behavior. For example: class Stream(object): def __init__(self, readable, writable): if readable and writable: self.io_type = 'inout' elif readable: self.io_type = 'out' else: self.io_type = 'in' That code sets me to thinking I'll get good mileage from: class Stream(object): ... class InStream(object): ... class OutStream(object): ... class InOutStream(object): ... I always get myself into trouble when I try to design a class hierarchy *before* I see something like that. -- Neil Cerutti -- http://mail.python.org/mailman/listinfo/python-list