The Abstract Class:
package abstractclass.exanpleAs you can see, the abstract properties and methods are defined in an inner class called AbstractDefinitions. These definitions are enforced by the call to AbstractClassUtils.enforceAbstractClass() in the constructor. Any sub classes are forced to implement these properties and methods.
{
import abstractclass.util.AbstractClassUtils;
import flash.utils.describeType;
public class ExampleAbstractClass
{
public function ExampleAbstractClass() {
AbstractClassUtils.enforceAbstractClass(
this, ExampleAbstractClass,
AbstractDefinitions);
}
}
}
import mx.controls.Button;
import mx.core.UIComponent;
class AbstractDefinitions {
public static var THIS_STATIC_PROPERTY:UIComponent;
public var thisNonStaticProperty:String;
public static function test(name:String, val:int=0) : int {return 0}
public function nonStatic(blah:Button) : UIComponent {return null}
}
How it works... The utility class uses introspection to ensure that the Objects are defined correctly. Introspection can be a fairly expensive operation, so use this method with care. You can always removed the enforceAbstractClass call when you put the code into production.
If you'd like to use this technique in your own apps, you can download my utility here: abstractclass.swc.

1 comments:
Could you provide the code to your utility class so we're able to understand the cost of your solution?
Also, you mention the usage of an inner class - but - it looks like this is just a separate class... Not a proper inner class.
A bit more description and source would be very helpful in assisting those of us trying to understand your thinking.
Post a Comment