德尔福的AOP支持 [英] AOP support in Delphi

查看:127
本文介绍了德尔福的AOP支持的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以在Delphi中进行面向方面的编程?我将对本地支持和第三方解决方案感兴趣。



我没有一个具体的问题,我想用AOP解决,但我只是兴趣学习AOP。

解决方案

AOP取决于两件事:




  • 将额外的代码注入到现有的代码单元中的能力

  • 一种机制来放置代码应注入的条件。



    • 这通常被称为代码编织。在程序转换的较大研究中,它是一个专门化。



      JIT编译语言比静态编译程序更多地实现代码编织,因为更多的信息保留在字节码/ IL。它们还支持反射,它提供了在运行时操作代码的能力。



      Delphi.NET和Prism具有与任何其他.NET语言相同的访问权限。 / p>

      我知道有两个Delphi Win32的AOP框架。第一个是已经提到的 MeAOP 。第二个是 Infra 。这两个项目都采用与AOP类似的方法。他们使用RTTI和巧妙的指针操作的组合来截取方法调用,以便您可以在方法调用之前或之后运行其他代码。您将交叉切割功能定义为框架AOP类的子类。通过将方法名称作为字符串参数传递给AOP框架,您可以注册要拦截的方法。



      这两个框架仍然是积极开发的,其范围实际上比只是AOP。不幸的是,文档有点稀疏(而在Infra的情况下,大多数是葡萄牙语)



      另一个项目通过源代码尝试AOP,并在2004年取得了一些成功。基本上,他们在名为DMS的通用程序转换工具之上构建了一个方面的编织器,并使用它在编译之前将代码注入到delphi源文件中。他们面向方面的语言主要受AspectJ的影响。



      http://www.gray-area.org/Research/GenAWeave/ 链接到原始论文和演示文稿以及转换过程的一些视频。



      也可以使用运行时代码检测来完成此操作。它是一些技术使用的技术,将计数器和堆栈跟踪注入到运行代码中,而无需修改原始源。可以使用类似的技术将横切关注点注入到静态编译的可执行文件中。 PinTool 项目是一个很好的例子。


      Is it possible to do Aspect Oriented Programming in Delphi? I would be interested in native support as well as third party solutions.

      I don't have a specific problem I want to solve with AOP, but am simply interested in studying AOP.

      解决方案

      AOP depends on two things:

      • The ability to inject additional code into an existing unit of code
      • A mechanism to place conditions on where code should be injected.

      This is commonly referred to as code weaving. It is a specialization within the larger study of program transformation.

      JIT compiled languages have more options for implementing code weaving than statically compiled programs because more information is retained in the bytecode/IL. They also support reflection, which offers the ability to manipulate code at runtime.

      Delphi.NET and Prism have the same access to these capabilities as any other .NET language.

      There are two AOP frameworks for Delphi Win32 that I'm aware of. The first is MeAOP, which has already been mentioned. The second is Infra. Both projects take a similar approach to AOP. They use a combination of RTTI and clever pointer manipulation to intercept method calls so you can run additional code before or after the method call. You define your cross-cutting feature as a subclass of the framework's AOP class. You register the methods you want intercepted by passing the method name as a string argument to the AOP framework.

      Both frameworks are still actively developed and are actually larger in scope than just AOP. Unfortunately documentation is somewhat sparse (and in Infra's case mostly in Portuguese)

      Another project attempted AOP through source code weaving back in 2004 with some success. Basically they built an aspect weaver on top of a general purpose program transformation tool called DMS and used it to inject code into delphi source files prior to compilation. Their aspect oriented language was primarily influenced by AspectJ.

      http://www.gray-area.org/Research/GenAWeave/ has links to the original paper and presentation as well as some videos of the transformation process.

      It may also be possible to use runtime code instrumentation to accomplish this as well. Its a technique used by some profilers to inject counters and stack traces into running code without modifying the original source. A similar technique could be used to inject crosscutting concerns into a statically compiled executable. The PinTool project is a good example of this.

      这篇关于德尔福的AOP支持的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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