Multiple Inheritance in ActionScript 3? Is it possible? I have read somewhere that it is possible in as3.
If yes then how?
this is my Doucument Class A.as
package
{
import flash.display.MovieClip;
public class A extends MovieClip implements B
{
public var value1:Number=10;
public function A()
{
trace("A Class Constructor");
}
public function hit():void
{
trace(value1+' from hit');
}
}
}
Another is interface B.as
package
{
public interface B
{
trace(' interface ');
function hit():void;
}
}
Thanks in advance.
Multiple inheritance is not possible in AS. But with interfaces you can mimic some of the functionality of multiple inheritance. MI has major flaws, most notably the diamond problem:
http://en.wikipedia.org/wiki/Diamond_problem
That’s why many languages don’t support MI, but only single inheritance.
Using interfaces it “appears” you apply MI, but in reality that is not the case since interfaces don’t provide an implementation, but only a promise of functionality.
P.S.: In case you’d wonder:
There’s no diamond problem with interfaces since an implementor of the interfaces must provide exactly one implementation of each member defined in the interfaces. So, even if both interfaces would define the same member (with identical signature of course) there will still be only one implementation.