AOP introduced a new way to do wishful thinking

王朝java/jsp·作者佚名  2006-01-10
窄屏简体版  字體: |||超大  

http://spaces.msn.com/members/nctaowen/

The essence of AOP is the idea: when x, do y. It gives you the power to insert any code at any place. It might change the way you think given the ability to introduce new things after you written them. Actually, I do think it will change the way to design, as you can do wishful thinking but not relying on additional parameters (these parameters may be somewhat higher-order function in functional programming or other object instance in object-oriented programming). With AOP, you can write down methods of class but not implement them. By weaving aspects later, the behavior can be fully implemented. This is different from traditional ways, in the past, you have to specifiy which one to call or use at the point you want to call or use them. By using AOP, you can define a method local to the object, and leave it blank. You give it some meanings, which may be a comlex collaboration between serval objects. But whatever the meaning is (or say pre-defined contracts), the method is still blank. You call it when you want to take the action which is binded to it in mind. Then, after you finished the work of designing the class, you can define a aspect to weave the behavior to the blank method. Now, you see AOP gives you a new power to use something before it is implemented, hence allows you to do wishful thinking which is the key to think and design complex computer programs.

I wrote a sample project which only doese trivial printing. You can download it at

http://www.cnblogs.com/Files/taowen/experiment.zip

public class ClassA {

public void doSomething() {

System.out.println("going to do something");

takeAction();

System.out.println("have done something");

}

@TakeAction

private void takeAction() {

}

}

when writing ClassA you don not care with who and how to take the action.

public aspect ABCollaboration {

ClassB b = new ClassB();

void around() : (call (@TakeAction * * (..))) {

b.doSomething();

}

public static void main(String[] args) {

new ClassA().doSomething();

}

}

By using a aspect, you weave the behavior later.

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
 
 
© 2005- 王朝網路 版權所有 導航