AS3 - Abstract Classes

前端 未结 2 822
借酒劲吻你
借酒劲吻你 2021-02-11 17:21

How can I make an abstract class in AS3 nicely?

I\'ve tried this:

public class AnAbstractClass
{
    public function toBeImplemented():void
    {
                


        
2条回答
  •  广开言路
    2021-02-11 17:42

    package 
    {
        import flash.errors.IllegalOperationError;
        import flash.utils.getDefinitionByName;
        import flash.utils.getQualifiedClassName;
        import flash.utils.getQualifiedSuperclassName;
    
        public class AbstractClass 
        {
            public function AbstractClass()
            {
                inspectAbstract();
            }
    
            private function inspectAbstract():void 
            {
                var className : String = getQualifiedClassName(this);
                if (getDefinitionByName(className) == AbstractClass ) 
                {
                    throw new ArgumentError(
                    getQualifiedClassName(this) + "Class can not be instantiated.");
                }
            }
    
            public function foo():void
            {
                throw new IllegalOperationError("Must override Concreate Class"); 
            }
        }
    }
    

    package
    {
        public class ConcreteClass extends AbstractClass
        {
            public function ConcreteClass()
            {
                super();
            }
    
            override public function foo() : void 
            {
                trace("Implemented");
            }
       }
    }
    

提交回复
热议问题