AS3 - 抽象类抽象类

2023-09-08 13:20:40 作者:再也不见

我怎样才能使一个抽象类,在AS3很好?

How can I make an abstract class in AS3 nicely?

我已经试过这样:

public class AnAbstractClass
{
    public function toBeImplemented():void
    {
        throw new NotImplementedError(); // I've created this error
    }
}

public class AnConcreteClass extends AnAbstractClass
{
    override public function toBeImplemented():void
    {
        // implementation...
    }
}

但是..我不喜欢这种方式。而且没有编译时错误。

But.. I don't like this way. And doesn't have compile time errors.

推荐答案

抽象类不支持的动作3.看http://joshblog.net/2007/08/19/enforcing-abstract-classes-at-runtime-in-actionscript-3/

abstract classes are not supported by actionscript 3. see http://joshblog.net/2007/08/19/enforcing-abstract-classes-at-runtime-in-actionscript-3/

以上参考还提供了一种解决办法的hackish要在AS3创建抽象类。

the above reference also provides a kind of hackish workaround to create abstract classes in as3.

修改 也看到http://www.kirupa.com/forum/showpost.php?s=a765fcf791afe46c5cf4c26509925cf7&p=1892533&postcount=70

Edit also see http://www.kirupa.com/forum/showpost.php?s=a765fcf791afe46c5cf4c26509925cf7&p=1892533&postcount=70

编辑2 (在回应评论)

不幸的是,你坚持的运行时错误。一种替代的会的是有一个受保护的构造....除了AS3不允许,要么。请参阅http://www.bernie$c$c.com/blog/2007/11/28/proper-private-constructors-for-actionscript-30/和http://gorillajawn.com/word$p$pss/2007/05/21/actionscript-3-%E2%80%93-no-private-constructor/.

Unfortunately, you're stuck with the runtime error. One alternative would be to have a protected constructor.... except as3 doesn't allow that either. See http://www.berniecode.com/blog/2007/11/28/proper-private-constructors-for-actionscript-30/ and http://gorillajawn.com/wordpress/2007/05/21/actionscript-3-%E2%80%93-no-private-constructor/.

您也可以找到这些有用的:http://www.as3dp.com/category/abstract-classes/和,特别是http://www.as3dp.com/2009/04/07/design-pattern-principles-for-actionscript-30-the-dependency-inversion-principle/

You may Also find these useful: http://www.as3dp.com/category/abstract-classes/ and, in particular, http://www.as3dp.com/2009/04/07/design-pattern-principles-for-actionscript-30-the-dependency-inversion-principle/