AOP introduced a new way to do wishful thinki…
2008-02-23 09:29:33来源:互联网 阅读 ()
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://image.21tx.com/files/20050819/25772.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.
上一篇: EJB3.0初步之Stateless session bean
下一篇: osworkflow api 之 util
标签:
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com
特别注意:本站所有转载文章言论不代表本站观点,本站所提供的摄影照片,插画,设计作品,如需使用,请与原作者联系,版权归原作者所有
IDC资讯: 主机资讯 注册资讯 托管资讯 vps资讯 网站建设
网站运营: 建站经验 策划盈利 搜索优化 网站推广 免费资源
网络编程: Asp.Net编程 Asp编程 Php编程 Xml编程 Access Mssql Mysql 其它
服务器技术: Web服务器 Ftp服务器 Mail服务器 Dns服务器 安全防护
软件技巧: 其它软件 Word Excel Powerpoint Ghost Vista QQ空间 QQ FlashGet 迅雷
网页制作: FrontPages Dreamweaver Javascript css photoshop fireworks Flash