Code: Select all
It is precisely the fact that interfaces don't have code that makes it possible for objects to inherit from multiple interfacesThe difference is due to the way polymorphism works (which uses late call binding):http://ca.php.net/interfaces wrote:A class cannot implement two interfaces that share function names, since it would cause ambiguity.
http://blogs.msdn.com/davidklinems/arch ... nding.aspx
Whereas interfaces are probably checked at compile-time, and therefore the ambiguity is detected. At least I think this is how it works in less dynamic languages, like C++.
C++ does MI but it also comes with the diamond of death problem:C++ does it. I think that's what ~arborint was getting at. Multiple inheritance isn't at all necessary
http://www.codeproject.com/KB/architect ... bject.aspx
Which is what PHPHorizonswas getting at.
You can achieve the same effect using single inheritence.Useful for content URLs, user profile URLs, etc. However, you don't want it to be a global function. In order to include it in only a few classes, you would need an external "formatting" dummy class, or to re-implement the method in all of the classes that need it. That, or make it into a global function. Multiple inheritance lets you write the code once and give it to any class that needs it.
MI is appealing to most developers for all the wrong reasons, in fact most of the time I have ever wanted to use it, what I really wanted was a mixin, because the MI class was essentially acting as an adapter for two or more classes, not actually needing to take advantage of multiple "inheritence" in and of it's self.
Cheers,
Alex