1 / 39

Towards A Better Organization of Programs with Aspect-Oriented Programming

This article provides an overview of aspect-oriented programming (AOP) and its benefits in controlling tangling and scattering in programs. It also showcases examples and tools for AOP.

tiano
Download Presentation

Towards A Better Organization of Programs with Aspect-Oriented Programming

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. Towards A Better Organization of Programs withAspect-Oriented Programming Karl Lieberherr Demeter Research Group Aspect-Oriented Programming

  2. Overview • Aspect-Oriented Programming (AOP): Crosscuting concerns, controlling tangling and scattering. • Example: 3 concerns: Find undefined entities. • Tools for AOP • AspectJ from Xerox PARC • DJ from Northeastern • Adaptive Programming and AOP • Summary Aspect-Oriented Programming

  3. The MIT Technology Review Ten (Jan./Feb. 2001 issue) • Ten emerging technologies that will change the world • Untangling Code - Aspect-Oriented Programming (AOP) • Data Mining • Micro Fluids • Robot Design • ... Aspect-Oriented Programming

  4. Northeastern Connection • Crista Lopes wrote the first Ph.D. Thesis on AOP at Northeastern supported by Xerox PARC. • The Demeter Research Group worked with interesting AOP Systems long before the name AOP was invented. Aspect-Oriented Programming

  5. Quote: MIT Technology Magazine • “The idea of aspects has been around for many years and with many different names. It is called adaptive programming at Northeastern University, and subject-oriented programming at IBM, …” Aspect-Oriented Programming

  6. AOP • Crosscutting concerns • Example: Logging: record every operation an application performs • “When adding a new operation to this application, always put a trace statement in” • Keeping track of crosscutting concerns is error-prone Aspect-Oriented Programming

  7. AOP • Crosscutting concerns, when implemented in an ad-hoc way, lead to a lot of tangling and scattering in the program. • Goal of AOP is to control the tangling and scattering in the program. Aspect-Oriented Programming

  8. Tangling: count color changes ordinary program better program structure-shy functionality Components structure Aspect 1 synchronization Aspect 2 Aspect-Oriented Programming

  9. Scattering: count number of modules to which color goes ordinary program better program structure-shy functionality M1 Components structure Aspect 1 M2 M3 synchronization Aspect 2 Aspect-Oriented Programming

  10. Aspect-Oriented Programming:Example • Separating the following cross-cutting concerns: • Object Structure • Traversals through Objects • Advice on Traversals • Focus on those three concerns only. They appear frequently. Aspect-Oriented Programming

  11. 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 Aspect-Oriented Programming

  12. Keeping Track • When object structure changes at certain places, need to update traversal. • Error prone. Aspect-Oriented Programming

  13. 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 Aspect-Oriented Programming

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

  15. Example • Check whether all used entities are defined. • Object structure, traversal, advice on traversal Aspect-Oriented Programming

  16. Find undefined things definedThings * System * Thing usedThings * * * UsedThingsHolder definedThings= from System bypassing UsedThingsHolder to Thing usedThings = from System through UsedThingsHolder to Thing Aspect-Oriented Programming

  17. Name map Aspect-Oriented Programming

  18. Java Program with less tangling class Cd_graph{ String vi = “from Vertex to edu.neu.ccs.demeter.Ident”; void isDefined(ClassGraph cg){ checkDefined(cg, getClasses(cg));} HashSet getClasses(ClassGraph cg){ String definedThings = "fromCd_graphbypassingNeighborstoVertex"; Visitor v = new Visitor(){ HashSet return_val = new HashSet(); void before(Vertexv1){ 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 Aspect-Oriented Programming

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

  20. Tangling is localized • 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. Aspect-Oriented Programming

  21. definedThings = from ClassG bypassing Body to ClassName UML class diagram ClassG 0..* Entry EParse entries ClassG BParse ClassDef Body parts Part className 0..* ClassName Concrete Abstract Aspect-Oriented Programming

  22. usedThings = from ClassG through Body to ClassName UML class diagram ClassG 0..* Entry EParse entries ClassG BParse ClassDef Body parts Part className 0..* ClassName Concrete Abstract Aspect-Oriented Programming

  23. usedThings = from EquationSystem through Expression to Variable Example: x = 1.0 . y = (+ x 4.0). z = (* x y). 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. Aspect-Oriented Programming

  24. definedThings= from EquationSystem bypassing Expression to Variable Example: x = 1.0 . y = (+ x 4.0). z = (* x y). 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. Aspect-Oriented Programming

  25. AspectJ (Xerox PARC) • A general aspect-oriented programming language for Java. • An aspect is like a class and may contain pointcut definitions defining a set of join points and advice saying what to do before, after or instead of the join points. Aspect-Oriented Programming

  26. DJ (Northeastern) • Is a Java package that supports AOP for the three concerns: class structure, traversals, and traversal advice. • Connection to AspectJ: both can be used simultaneously. • DJ provides an implementation of Adaptive Programming (AP). Aspect-Oriented Programming

  27. Principle behind AP: Polya’s Inventor Paradox • Polya observed that it is often easier to solve a more general problem than the one at hand and then to use the solution of the general problem to solve the specific problem. The hard work consists of finding the appropriate generalization. • Programs become shorter and more powerful. A paradox. With less work we achieve more. Aspect-Oriented Programming

  28. Apply Polya to Programming • Generalization: Don’t write the program for a specific data structure, write it for an abstract data structure. Aspect-Oriented Programming

  29. Concepts needed(DJ classes) • ClassGraph • Strategy • ObjectGraph • ObjectGraphSlice • Visitor Aspect-Oriented Programming

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

  31. Adaptive Programming Strategy defines traversals of ObjectGraph plus Strategy defines ObjectGraphSlice Aspect-Oriented Programming

  32. Adaptive Programming Strategy guides and informs Visitor Aspect-Oriented Programming

  33. 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) Aspect-Oriented Programming

  34. 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 join point reduction. Example: structure-shyness AOP AP Aspect-Oriented Programming

  35. 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 Aspect-Oriented Programming

  36. Benefits of Adaptive Programming • robustness to changes • shorter programs • design matches program, • more understandable code • partially automated evolution • keep all benefits of OO technology • improved productivity Applicable to design and documentation of your current systems. Aspect-Oriented Programming

  37. Summary • AOP getting a lot of attention. Addresses an important problem: how to program crosscutting concerns. • AP is about relieving the programmer from the details of a concern: traditionally from the structural concern. • Want to learn more: Take COM 3360: Adaptive Object-Oriented Software Development and attend the Demeter Seminar. Aspect-Oriented Programming

  38. Current Work • DARPA grant with BBN (Prof. Wand, Lieberherr) on AOP for real-time systems. • Doug Orleans: PhD thesis, in progress: Design and Implementation of Aspect-Oriented Languages. • Johan Ovlinger: PhD thesis, in progress: The Collaboration/Adapter Approach to AOP. Works with industry: SKYVA. Aspect-Oriented Programming

  39. Critical Mass • Professors: Lorenz, Wand, Lieberherr, Clinger • Ph.D. students: Orleans, Ovlinger, Wu • Master’s students working on JSR 31 project: Prasenijt Adak, Huichan He, John Sung • Undergraduate student: Jon Kelley • Courses: COM 3360 (graduate), COM 1205 (undergraduate) Aspect-Oriented Programming

More Related