Bruno Desthuilliers wrote: > neoedmund wrote: > (snip) > > So I can reuse a method freely only if it's worth reusing. > > For the word "inheritance", in some aspect, meanings reuse the super > > class, with the condition: must reuse everything from super class. > > Not really. In fact, inheritance *is* a special case of > composition/delegation. A 'child' class is a class that has references > to other classes - it's 'parents' -, and then attributes that are not > found in the instance or child class are looked up in the parents > (according to mro rules in case of multiple inheritance). And that's all > there is. > > > It's lack of a option to select which methods are to be reused. > > Methods not redefined in the 'child' class or it's instance are > 'reusable'. Now they are only effectively 'reused' if and when called by > client code. So the 'option to select which methods are to be reused' is > mostly up to both the 'child' class and code using it. > > > this is something should be improved for general OOP i think. > > So to answer " What is your problem with having the other extra methods > > too ?", > > in real life, a class is not defined so well that any method is needed > > by sub-class. > > Then perhaps is it time to refactor. A class should be a highly cohesive > unit. If you find yourself needing only a specific subset of a class, it > may be time to extract this subset in it's own class. Given Python's > support for both multiple inheritance and composition/delegation, it's > usually a trivial task (unless you already mixed up too many orthogonal > concerns in your base class...). > > -- > bruno desthuilliers > python -c "print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for > p in '[EMAIL PROTECTED]'.split('@')])"
ivestgating the web, i found something similiar with my approch: http://en.wikipedia.org/wiki/Duck_typing "Duck-typing avoids tests using type() or isinstance(). Instead, it typically employs hasattr() tests" -- http://mail.python.org/mailman/listinfo/python-list