
From: "Guido van Rossum" <guido@python.org>
We'd need a trick to deny an interface that would be inherited by default. Something like private inheritance.
I think it's more than that. You might need to "uninherit": Say Interface A begets class B which begets class C. What if C doesn't fulfill A?
Sorry, I meant to include that case. How do you do that in C++?
We don't use inheritance for this kind of interface. When we're making a Java-style interface, sure, inheritance works fine in C++. However, because of Python's dynamic, generic nature what we've been calling an interface for Python is much more like a "concept", which has no direct expression in code: http://www.boost.org/more/generic_programming.html#concept Actually if you read a little further on down the page (the Traits and Tag Dispatching sections), you'll see that it's possible to create an expression in code of a concept in C++. Usually you want to do that when concepts form a refinement hierarchy (e.g. bidirectional_iterator refines forward_iterator) which may or may not correspond to inheritance relationships.
Inherit privately from B and publicly from A, and making A virtual base everywhere?
I guess you /could/ do that. I don't think anyone does, though ;-) I was going to say that is seems to me if you can dynamically inject base classes in Python there's no problem using inheritance to do this sort of labelling. However, on third though, maybe there is a problem. Suppose you have an inheritance chain A->B->C...->Z and I come a long later to say that A fulfills interface II and add II to A's bases. Which of A's subclasses also fulfill II. I might not know. I might not even know about them. For this, maybe you'd need a way to express inheritance that goes just "one level deep" (i.e. A inherits II publicly, but nothing else does). And that might just screw with the notion of inheritance enough that you want a separate parallel mechanism. So I guess I'm back to where I was before. Inheritance probably doesn't work out too well for expressing "satisfies interface". ----------------------------------------------------------- David Abrahams * Boost Consulting dave@boost-consulting.com * http://www.boost-consulting.com