Make an AS3/Flex class Extendable but not Instantiatable as an object?
I have a class SuperClass
that implements an interface, and has all the public methods of the interface implemented. I have another class SubClass
that extends SuperClass
. I dont want those public methods being used incorrectly. This leads to my question:
How do I prevent SuperClass
from ever being instantiated as an object?
Brian
Update: Using hint from answer below, solution is:
public function MyClass():void
{
if(getQualifiedClassName(this) == "ui.controls::MyClass")
{
throw 开发者_如何学Cnew Error('MyClass is an abstract class, do ' +
'not instantiate');
}
}
AS3 does not support abstract classes. The best you can do is runtime enforcement. Check out this post for more info.
精彩评论