1 / 37

Slides for Gregor Kiczales

Slides for Gregor Kiczales. Two versions short version: Crosscutting capabilities for Java and AspectJ through DJ (4 viewgraphs only) long version: Controlling tangling and scattering. Crosscutting Capabilities for Java and AspectJ through DJ. Demeter Team.

Télécharger la présentation

Slides for Gregor Kiczales

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Slides for Gregor Kiczales • Two versions • short version: Crosscutting capabilities for Java and AspectJ through DJ (4 viewgraphs only) • long version: Controlling tangling and scattering ... DJ

  2. Crosscutting Capabilities for Java and AspectJ through DJ Demeter Team DJ

  3. Class graph: Find undefined things definedThings System * Thing * usedThings * * Definition Body definedThings= from System bypassing Body to Thing usedThings = from System through Body to Thing DJ

  4. Java Program: Aspectual Method with DJ class System{ String vi = “from Thing to edu.neu.ccs.demeter.Ident”; void isDefined(ClassGraph cg){ checkDefined(cg, getClasses(cg));} HashSet getClasses(ClassGraph cg){ String definedThings = "fromSystembypassingBodytoThing"; Visitor v = new Visitor(){ HashSet return_val = new HashSet(); void before(Thingv1){ return_val.add(cg.fetch(v1, vi) );} public Object getReturnValue(){return return_val;}}; cg.traverse(this,definedThings, v); return (HashSet)v.getReturnValue(); } isDefined is a modular unit of crosscutting implementation. Ad-hoc implementation may cut across 100 classes. green: traversal black bold: structure purple: advice red: parameters DJ

  5. Java Program: Aspectual Method with DJ void checkDefined(ClassGraph cg, final HashSet classHash){ String usedThings = ”fromSystemthroughBodytoThing"; cg.traverse(this, usedThings, new Visitor(){ void before(Thingv){ Ident vn = cg.fetch(v, vi); if (!classHash.contains(vn)){ System.out.println("The object "+ vn + " is undefined."); }}});} } DJ

  6. What DJ adds to AspectJ • Point cut definitions based on connectivity in class graph. • Define point cuts by specifying a (traversal) program based on class graph. • Point cut reduction (high-level point cut designator): free programmer from details of class graph. Free programmer from detail of some aspect. DJ

  7. Control Tangling and Scattering of Class Structure, Traversals andTraversal Advice Feb. PI Meeting DJ

  8. Aspect-Oriented Programming • Separating the following cross-cutting concerns: • Object Structure • Traversals through Objects • Advice on Traversals • New behaviors based on collaborating objects • Focus on those four concerns only. They appear frequently. DJ

  9. overall graph: object structure; green graph: traversal; purple: advice Why crosscutting? r=0; :BusList Route1:BusRoute buses busStops :BusStopList Bus15:DieselPowered passengers CentralSquare:BusStop waiting :PersonList :PersonList Joan:Person Paul:Person Seema:Person r++; r++; Eric:Person DJ

  10. Why aspects: Oblivious • Object Structure • does not have to know about traversals and advice on traversals • Traversals • don’t have to know about advice on traversals • Advice on Traversals • has to know minimally about object structure and traversals DJ

  11. Ad-hoc Implementationof three concerns • Leads to lots of tangled code with numerous disadvantages • The question is not how to eliminate the tangling but how to reduce it • AOP is about tangling control the implementation of crosscutting concerns • Crosscutting will always lead to some tangling at code level DJ

  12. Example • Check whether all used entities are defined. • Object structure, traversal (basically an introduction), advice on traversal DJ

  13. Find undefined things definedThings System * Thing * usedThings * * Definition Body definedThings= from System bypassing Body to Thing usedThings = from System through Body to Thing DJ

  14. Name map Definition ClassDef Production Equation DJ

  15. High-level description • It is useful to have a high-level description of the collaboration besides the Java source code. Useful documentation. • Ultimately we are interested in the executable form of the collaboration (Java source code). DJ

  16. Collaboration with strategies collaboration checkDef { roleSystem { out isDefined(){(uses getClasses, checkDefined)}; getClasses(){(uses definedThings)}; checkDefined(){(uses usedThings)}; in definedThings = from System bypassing Body to Thing; inusedThings = from System through Body to Thing; } roleBody { } roleThing { } roleDefinition { } } DJ

  17. Use of collaboration: Adapter Need to provide the expected methods (in methods) and provide name map. • name map: • System : EquationSystem • Definition : Equation • Body : Expression • Thing : Variable • expected methods: • in definedThings // use default • inusedThings // use default DJ

  18. What is an aspect? • An aspect is a modular unit of crosscutting implementation. • A Java method is a modular unit. • Can we make a Java method an aspect? • Yes, we call such methods aspectual methods. • They cut across many classes in an ad-hoc implementation. DJ

  19. Java Program: Aspectual Method class System{ String vi = “from Thing to edu.neu.ccs.demeter.Ident”; void isDefined(ClassGraph cg){ checkDefined(cg, getClasses(cg));} HashSet getClasses(ClassGraph cg){ String definedThings = "fromSystembypassingBodytoThing"; Visitor v = new Visitor(){ HashSet return_val = new HashSet(); void before(Thingv1){ return_val.add(cg.fetch(v1, vi) );} public Object getReturnValue(){return return_val;}}; cg.traverse(this,definedThings, v); return (HashSet)v.getReturnValue(); } green: traversal black bold: structure purple: advice red: parameters DJ

  20. Java Program: Aspectual Method void checkDefined(ClassGraph cg, final HashSet classHash){ String usedThings = ”fromSystemthroughBodytoThing"; cg.traverse(this, usedThings, new Visitor(){ void before(Thingv){ Ident vn = cg.fetch(v, vi); if (!classHash.contains(vn)){ System.out.println("The object "+ vn + " is undefined."); }}});} } DJ

  21. After applying name map • For now we manually edit the Java program. DJ

  22. Java Program with less tangling class EquationSystem{ String vi = “from Variable to edu.neu.ccs.demeter.Ident”; void isDefined(ClassGraph cg){ checkDefined(cg, getClasses(cg));} HashSet getClasses(ClassGraph cg){ String definedThings = "fromEquationSystembypassingExpressiontoVariable"; Visitor v = new Visitor(){ HashSet return_val = new HashSet(); void before(Variablev1){ return_val.add(cg.fetch(v1, vi) );} public Object getReturnValue(){return return_val;}}; cg.traverse(this,definedThings, v); return (HashSet)v.getReturnValue(); } green: traversal black bold: structure purple: advice red: parameters DJ

  23. Java Program with less tangling void checkDefined(ClassGraph cg, final HashSet classHash){ String usedThings = ”fromEquationSystemthroughExpressiontoVariable"; cg.traverse(this, usedThings, new Visitor(){ void before(Variablev){ Ident vn = cg.fetch(v, vi); if (!classHash.contains(vn)){ System.out.println("The object "+ vn + " is undefined."); }}});} } DJ

  24. Tangling is localizedScattering eliminated • Instead of having code spread across several classes, it is localized in one class. • Java program is describing the abstract pattern behind the computation of interest: checking whether used entities are defined. • Tangling control through abstraction of patterns. We abstract away from structure. DJ

  25. definedThings = from ClassG bypassing Body to ClassName CS1: UML class diagram ClassG 0..* Entry EParse entries ClassG BParse ClassDef Body parts Part className 0..* ClassName Concrete Abstract DJ

  26. usedThings = from ClassG through Body to ClassName CS1:UML class diagram ClassG 0..* Entry EParse entries ClassG BParse ClassDef Body parts Part className 0..* ClassName Concrete Abstract DJ

  27. usedThings = from EquationSystem through Expression to Variable Example: x = 1.0 . y = (+ x 4.0). z = (* x y). M1: Equation System EquationSystem = <equations> List(Equation). Equation = <lhs> Variable “=“ <rhs> Expression “.”. Variable = Ident. Expression : Simple | Compound. Simple : Variable | Numerical. Compound = “(“ Op <args> List(Expression) “)”. Op : Add | Mul. Add = “+”. Mul = “*”. Numerical = float. DJ

  28. definedThings= from EquationSystem bypassing Expression to Variable Example: x = 1.0 . y = (+ x 4.0). z = (* x y). M1: Equation System EquationSystem = <equations> List(Equation). Equation =<lhs> Variable “=“ <rhs> Expression “.”. Variable = Ident. Expression : Simple | Compound. Simple : Variable | Numerical. Compound = “(“ Op <args> List(Expression) “)”. Op : Add | Mul. Add = “+”. Mul = “*”. Numerical = float. DJ

  29. DJ • Is a Java package that supports AOP for the three concerns: class structure, traversals, and traversal advice. • Tested by 50+ users. • Connection to AspectJ: both can be used simultaneously. DJ

  30. Concepts needed(DJ classes) • ClassGraph • Strategy • ObjectGraph • ObjectGraphSlice • Visitor DJ

  31. Adaptive Programming Strategy Bold names refer to DJ classes. is use-case based abstraction of ClassGraph defines family of ObjectGraph DJ

  32. Adaptive Programming Strategy defines traversals of ObjectGraph plus Strategy defines ObjectGraphSlice DJ

  33. Adaptive Programming Visitor advises Traversal DJ

  34. Abstract pointcut set of execution points where to watch Advice what to do Concrete pointcut set notation using regular expressions Abstract object slice set of entry/exit points where to go Visitor what to do Actual object slice traversal strategies AspectJ (Xerox) DJ (NEU) DJ

  35. Program with aspects that correspond to the concerns of the programmer. Relieve the programmer from the details of some concern. Create robustness to changes in an aspect. AP is about point cut reduction. Example: structure-shyness AOP AP DJ

  36. Technology Evolution Object-Oriented Programming Tangled structure/behaviors robustness to structure changes Other Technologies Adaptive Programming Tangled concerns in general (synchronization, etc.) Aspect-Oriented Programming robustness to aspect changes Aspect-Oriented Programming II DJ

  37. What DJ adds to AspectJ • Point cut definitions based on connectivity in class graph. • Define point cuts by specifying a (traversal) program based on class graph. • Point cut reduction (high-level point cut designator): free programmer from details of class graph. DJ

More Related