Aspects at the Design Level 2003. 05. 21. SNU., RTOSLAB. Jiyong Park
Contents Modeling Aspect Mechanisms Representing aspect in UML The big picture of our framework Limitations of existing methods Proposed better methods Conclusion
Modeling Aspect Mechanisms Modular Crosscutting in Aspect-Oriented Mechanisms Hidehiko Masuhara – University of Tokyo Gregor Kiczales – University of British Columbia ECOOP 2003
Contents Brief descriptions of four aspect mechanisms Pointcut, Advice Traversal Specification Class hierarchy composition Open class Model of each mechanisms
Four Different Aspect Mechanisms Pointcut, Advice – AspectJ Traversal specification – Demeter, DemeterJ, DJ Class hierarchy composition – Hyper/J Open class – AspectJ
Pointcut, Advice execute display.update() whenever after set*() is called Figure FigureElement 1 * elements: List display: Display Point Line x: int y: int 2 p1: Point p2: Point getX(void): int getY(void): int setX(int x): void setY(int x): void getX(void): int getY(void): int setP1(Point p1): void setP2(Point p2): void
Pointcut, Advice Advice: additional implementation Pointcut: the location that the advice is to be inserted after (FigureElement fe): call(void FigureElement+.set*(..)) && target(fe) { fe.display.update(fe); } Figure FigureElement 1 * elements: List display: Display Point Line x: int y: int 2 p1: Point p2: Point getX(void): int getY(void): int setX(int x): void setY(int x): void getX(void): int getY(void): int setP1(Point p1): void setP2(Point p2): void DisplayUpdating after(): call(void FigureElement+.set*(..)) || call(void FigureElement.moveBy(int, int)) { Display.update(); }
Traversal Specification find all persons waiting at any bus stop on a bus route busStops BusRoute BusStopList OO solution: one method for each green class buses 0..* BusStop BusList waiting 0..* passengers PersonList Bus Person 0..*
Traversal Specification from BusRoute through BusStop to Person busStops BusRoute BusStopList buses 0..* BusStop BusList waiting 0..* passengers PersonList Bus Person 0..*
Traversal Specification Build a object graph (based on reachability) at runtime Traversal specifiction: where to navigate Visitor: what to do before and after certain object is visited String WPStrategy=“from BusRoute through BusStop to Person” // Prepare the traversal for the current class graph ClassGraph classGraph = new ClassGraph(); TraversalGraph WPTraversal = new TraversalGraph (WPStrategy, classGraph); int r = aBusRoute.countPersons(WPTraversal);
Traversal Specification root of the traversal class BusRoute { int countPersons(TraversalGraph WP) { Integer result = (Integer) WP.traverse(this, new Visitor(){ int r; public void before(Person host){ r++; } public void start() { r = 0;} public Object getReturnValue(){return new Integer(r);} } ); return result.intValue();
Traversal Specification DJ Java Library (uses Reflection) Enables aspect programming in pure Java By Northeastern University
Class Hierarchy Composition Meta-Program (How to weave) Source A Source A+B weaver Source B
bracket “{Point,Line}”.”set*” after Observable.moved($OperationName); Program A Program B Figure FigureElement 1 * elements: List display: Display Point Line Observable x: int y: int 2 p1: Point p2: Point display: Display moved(): void { display.update(); } getX(void): int getY(void): int setX(int x): void setY(int x): void getX(void): int getY(void): int setP1(Point p1): void setP2(Point p2): void Meta-Program mergeByName; bracket “{Point,Line}”.”set*” after Observable.moved($OperationName);
Open Class Locate method or field declaration outside the textual body of the class declarion Synonym introduction (by AspectJ) inter-type declaration Common use Solve versions of the visitor problem class DisplayMethods { void Point.draw() { Graphics.drawOval(…);} void Line.draw() { Graphics.drawLine(…);} }
What is crosscutting structure ? program A and B crosscut each other = set of join points identified by program A and B is not a subset of the other Program A Weaved Program Program B join point
Modeling Framework <X, XJP, A, AID, AEFF, AMOD, B, BID, BEFF, BMOD, META> A, B: language that input program is written X: result of domain weaving process XJP: join points in X AID, BID: means of identifying join points AEFF, BEFF: means of effecting semantics at identified join points AMOD: BMOD: units of modularity META: optional meta-language for parameterizing the weaving process Program A Weaver Program X Program B Meta program
Modeling Framework kind of join points kind of join points
Pointcut, Advice class aspect execution method call field set/get object instantiated
Traversal Specification object graph class traversal specification & visitor
Class Hierarchy Composition combined program class method declaration field declaration class declaration meta program
Open Class class class open class method declaration field declaration class declaration
Conclusion Pointcut, Advice of AspectJ is most popular But, other mechanisms can give some insight Class hierarchy composition seems to be the most natural way
Our Aspect Weaving Framework
Key Ideas Automatically generate ‘weaver’ described by meta-model transform specification Represent aspects in graphical way
Key Idea 1: How to weave aspect ? metamodel of aspectJ model transformation (aspectJ Java) metamodel of Java metamodel model aspectJ program aspect weaver Java Program implementation oriented (traditional) approach intermediate stage metamodel of aspect program model tr. generic object metamodel model tr. metamodel of Java metamodel model code gen aspect program Generic object program Java Program design oriented (our) approach
Comparision Limitations of implementation oriented approach Weaver is dependent on language Hard to modify weaving process Our design oriented approach Intermediate model is introduced (generic object program) [generic object program implemention program] is naïve [aspect program generic object program], which is weaving process, is graphical
Related Work By Hidehiko Masuhara & Gregor Kiczales
Incorporating Aspects into the UML Mark Basch, Arturo Sanchez Department of Computer and Information Science, University of North Florida International Conference on Aspect-Oriented Software Development (AOSD), 2003 From AOP to UML – A Bottom-Up Approach Mohamed Mancona Kande, Jorg Kienzle and Alfred Strohmeier Software Engineering Laboratory Swiss Federal Institute of Technology Lausanne Workshop on Aspect-Oriented Modeling with UML (as part of the AOSD 2003)
Contents UML is not suitable for model aspect Example Extension to UML
Using UML for OO Modeling Well supported public class Account { private int balance = 0; public void withdraw (int amount) {…}; public void deposit (int amount) {…}; public int getBalance() {…}; } public class Customer { public String name; … a.withdraw(50); } (dynamic structure) (static structure)
Using UML for Aspect-Oriented Modeling Logging aspect: all method calls made by customers on an account object generates logs Not well supported public aspect Logging { private PrintWriter Account.myLog; public void Account.setLog(String fileName) { myLog = new Log(fileName); myLog.println(“This is the logfile for account “+ this); } pointcut MethodCall(Customer c, Account a): call (public * Account.*(..)) && this(c) && target(a); after (Customer c, Account a): MethodCall(c,a) { a.myLog.println(c+” called “+ thisJoinPoint.getSignature().getName()); a.myLog.flush();
Using UML for Aspect-Oriented Modeling
Problems of the Previous Modeling Aspect is scattered throughout the diagrams The two diagrams are inconsistent (Interceptor class) pointcut, introduction, advice are not explicitly modeled … Abstraction inversion In implementation: logging code is seperated In design: logging design is scattered
Modeling Aspect in UML Extending existing UML Using stereotype, tag, … Confusing Introduce new modeling element Clear
Extending Existing UML Designing Aspect-Oriented Crosscutting in UML Dominik Stein, Stefan Hanenberg, and Rainer Unland
Extending Existing UML From AOP to UML – A Bottom-Up Approach Mohamed Mancona Kandé, Jörg Kienzle and Alfred Strohmeier
Extending Existing UML A UML Notation for Aspect-Oriented Software Design Renaud Pawlak, Laurence Duchien, …
Introduce New Modeling Element Incorporating Aspects into the UML Mark Basch, Arturo Sanchez New elements join points aspects
1. Aspect Packages join points are modeled outside of aspect and component package
2. Class Diagrams for Aspects Within aspect package To show which component classes are cross-cut by the aspect
3. Interaction Diagrams for Aspects Interaction between component and aspect
3. Interaction Diagrams for Aspects Sequence inside the aspect
Future Work Bring new UML notation into our framework