Drenai
Drenai

Reputation: 12407

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 new Error('MyClass is an abstract class, do ' +
                                    'not instantiate');
     }           

}

Upvotes: 5

Views: 311

Answers (1)

RJ Regenold
RJ Regenold

Reputation: 1758

AS3 does not support abstract classes. The best you can do is runtime enforcement. Check out this post for more info.

Upvotes: 4

Related Questions