AS3 - 抽象类 [英] AS3 - Abstract Classes

查看:125
本文介绍了AS3 - 抽象类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我怎样才能使一个抽象类,在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.看<一href="http://joshblog.net/2007/08/19/enforcing-abstract-classes-at-runtime-in-actionscript-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.

修改
也看到<一href="http://www.kirupa.com/forum/showpost.php?s=a765fcf791afe46c5cf4c26509925cf7&p=1892533&postcount=70">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不允许,要么。请参阅<一href="http://www.bernie$c$c.com/blog/2007/11/28/proper-private-constructors-for-actionscript-30/">http://www.bernie$c$c.com/blog/2007/11/28/proper-private-constructors-for-actionscript-30/和<一href="http://gorillajawn.com/word$p$pss/2007/05/21/actionscript-3-%E2%80%93-no-private-constructor/">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/.

您也可以找到这些有用的:<一href="http://www.as3dp.com/category/abstract-classes/">http://www.as3dp.com/category/abstract-classes/和,特别是<一href="http://www.as3dp.com/2009/04/07/design-pattern-principles-for-actionscript-30-the-dependency-inversion-principle/">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/

这篇关于AS3 - 抽象类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆