Today I want to discuss my impression of AOP concept in Ruby.
I learned AOP from java, in java you have to use AspectJ or Dynamic Proxy implement AOP. But comapre to Java, I realize Ruby support AOP in the lanuage level:
- Classes are open: you add new method or attribute for any existing class, or replace the method with new one.
- Module and Mixin: you can easily add new functionalities by Mixin the module.
- MetaProgramming: you can dynamically define a method on the fly, using hook method as call back, easily implement before, after and around advice
So I will say AOP is built in support in Ruby language level.
Today I found a blog called "Does Ruby need AOP?", the author argue that Ruby metaprogramming is not AOP,because he think AOP is all about semantics, while Ruby metaprogramming is too low level. I feel this argument is too academic, from the pragmatic perspective, I think as long as Ruby can do the job of separation of concern, then it is AOP, then who care about the semantics?
Here are some useful links:
No comments:
Post a Comment