文档介绍:Aspect-Oriented Programming with AspectJ
Aspect-Oriented Programming
with AspectJ™
PARC
Erik Hilsdale, Jim Hugunin, Wes Isberg,
Gregor Kiczales, Mik Kersten
partially funded by DARPA under contract F30602-97-C0246
1 (c) Copyright 1998-2002 Palo Alto Research Center Incorporated. All Rights Reserved.
outline
• I AOP and AspectJ overview
– problems, basic concepts, context, adoption
• II AspectJ tutorial
– first example
– language mechanisms
– development environment
– using aspects
• III conclusion
– futures, references, summary
2 (c) Copyright 1998-2002 Palo Alto Research Center Incorporated. All Rights Reserved.
(c) Copyright 1998-2002 Palo Alto Research Center Incorporated. All Rights Reserved.
Aspect-Oriented Programming with AspectJ
good modularity
XML parsing
• XML parsing .
– red shows relevant lines of code
– nicely fits in one box
3 (c) Copyright 1998-2002 Palo Alto Research Center Incorporated. All Rights Reserved.
good modularity
URL pattern matching
• URL pattern matching .
– red shows relevant lines of code
– nicely fits in two boxes (using inheritance)
4 (c) Copyright 1998-2002 Palo Alto Research Center Incorporated. All Rights Reserved.
(c) Copyright 1998-2002 Palo Alto Research Center Incorporated. All Rights Reserved.
Aspect-Oriented Programming with AspectJ
problems like…
logging is not modularized
• where is logging .
– red shows lines of code that handle logging
– not in just one place
– not even in a small number of places
5 (c) Copyright 1998-2002 Palo Alto Research Center Incorporated. All Rights Reserved.
problems like…
session expiration is not modularized
ApplicationSession StandardSession
/* public void invalidate() { .; /**
* ==================================================================== (context); /** * Bind an object to this session, usin