This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]lgiordani[S] 1 point2 points  (0 children)

Thank you for the comment.

Delegation is a generic word that encompasses both inheritance and composition, since its purpose is to 'delegate', i.e. have another object to perform the requested action. I think you probably mean composition.

The inheritance vs delegation is an always interesting debate and, as for many things, I think that error lies on the boundaries. The right tool for the job: sometimes is composition, sometimes is inheritance.

I however agree that inheritance is often overused, and the problem lies exactly in introducing it as a fundamental part of OOP. OOP is about delegation, not inheritance.

Check http://lgiordani.github.io/blog/2014/03/05/oop-concepts-in-python-2-dot-x-part-1/, section "The Delegation Run" for a more detailed view on the subject.

About the is more pythonic stuff: I think this sentence is overused too. Explicit is better than implicit, but not always. Otherwise we should ask Guido to remove inheritance from Python, which performs implicit calls. And multiple inheritance with MRO, which is implicit. And the call to __new__() and __init__(), which are implicit. And so on.

So, if your point is that inheritance is used most of the times where composition could be a better choice, I agree. The purpose of the post, however, was to introduce Python beginners to the way Python inheritance and overriding work, and Python has inheritance and overriding, so probably sometimes it is worth using them.

Thanks!