面向方面的编程库/框架ActionScript 3的? [英] Aspect Oriented Programming Library/Framework for Actionscript 3?

查看:171
本文介绍了面向方面的编程库/框架ActionScript 3的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在寻找一个全功能AOP库为ActionScript 3。

I'm looking for a full featured AOP Library for Actionscript 3.

下面的项目中,我注意到,到目前为止,但他们都似乎有自己的问题:

The following projects I noticed so far, but they all seem to have their problems:

  • http://farmcode.org/page/Sodality.aspx
    looks most promising so far, however it requires you to create a whole new class for every AOP "call" I believe, and it forces you to follow quite a lot of restrictions, anyone has experience with it?
  • http://code.google.com/p/loom-as3/
    this one is discontinued
  • http://code.google.com/p/floxy/
    dynamic proxy generation? this isn't really AOP as I know it, right?
  • http://code.google.com/p/flemit/
    dynamic byte code generation? this is something AOP needs I think, but not the full featured AOP framework I am looking for

有谁知道一个更好的解决方案?或者有没有人有在ActionScript 3中使用AOP任何经验?

Does anyone know of a better solution? Or does anyone have any experiences with AOP in Actionscript 3?

最好的问候,

汤姆

推荐答案

AOP在ActionScript 3真的很难。所有aproaches有自己的问题:

AOP in ActionScript 3 is really hard. All aproaches have their problems:

  • 代理:实际工作正常,透明的程序员,而不是运行时。如果任何函数签名预计A类型的对象,然后键入的对象的代理将无法通过类型检测
  • 字节code世代:好,有点工作,但不太好。装载字节code在AVM2是异步的,所以你不能做到这一点的正是时候。此外,一旦字节code被加载时,有没有办法放弃它,所以你不能修改类第二次。
  • 在别的是verbous

你可以做的是使用 haXe的。不仅haXe的有超过的AS3其他优点,但它也允许一些AOP。有两种方法:

What you can do is to use haXe. Not only does haXe have other advantages over AS3, but it also allows some AOP. There are two approaches:

在haXe的,你可以声明方法是动态的。这些都可以在运行时提供建议更换。让我来解释一下,引擎盖下会发生什么。下面haXe的code:

In haXe, you can declare methods to be dynamic. These can be replaced at runtime to provide advices. Let me explain, what happens under the hood. The following haXe code:

public function foo(param1:Type1):Type2 { /*body*/ }
public dynamic function bar(param1:Type1):Type2 { /*body*/ }

是以下AS3 code相当于:

Is the equivalent of the following AS3 code:

public function foo(param1:Type1):Type2 { /*body*/ }
public var bar:Function = function (param1:Type1):Type2 { /*body*/ }

使用后者总是执行比前者差,因为有大量的运行时类型的检查涉及。在haXe的但是,你不失去严格类型的编译时好处,不像在AS3。

Using the latter always performs worse than the former, since there's a lot of runtime type checking involved. In haXe however, you do not lose the compile time benefits of strict typing, unlike in AS3.

同样,使用haXe的的访问(这确实是从AS3有很大不同),您还可以使用AOP的特性:

Likewise, using haXe's accessors (that are indeed very different from AS3's), you can also use AOP for properties:

public var foo(get_foo, set_foo):Type;
dynamic function get_foo() {//haXe will automatically infer types: http://haxe.org/ref/type_infer
    return this.foo;
}
dynamic function set_foo(param) {
    return this.foo = param;
}

任何方法,是动态的可替换在运行时做任何你想。 AS2允许这一点,像as2lib库提供AOP。不幸的是,它不再可用。但我猜你可以找出剩下的你自己。

Any methods, that are dynamic can be replaced at runtime to do whatever you wish. AS2 allowed this, and libraries like as2lib provided AOP. unfortunately, it is no longer available. But I guess you can figure out the rest on you own.

haXe的有匿名类型的。在运行时,这些仅仅是 * (因而性能比较的损失是可以预料的),但是在编译的时候,他们是类型安全的。你可以做的,就是创建一个代理的任何类型,你需要一个对象,并用它作为AOP的容器。在你的整个code,你永远不使用explicetely它的类型,而是一个等效匿名类型。我描述代理的问题将不复存在。你需要做的唯一的事情就是让一个不安全的投代理的该匿名类型。

haXe has the notion of anonymous types. At runtime, these are merely * (thus a perfomance loss is to be expected), but at compile time, they are type safe. What you can do, is create a proxy to an object of whatever type you need and use it as AOP container. In your whole code, you never use its type explicetely, but rather an equivalent anonymous type. The problem with proxying I described will be gone. The only thing you need to do is to make an unsafe cast of your proxy to that anonymous type.

希望帮助

格尔茨
back2dos

greetz
back2dos

这篇关于面向方面的编程库/框架ActionScript 3的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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