Aspect Oriented Development Alex Beatty Introduction Purpose Crosscutting
Aspect Oriented Development Alex Beatty
Introduction Purpose Cross-cutting Concerns Join Points, Pointcuts, and Advices Weaving Invasive vs. Non-Invasive Static vs. Dynamic
Purpose What is a cross-cutting concern? Examples Reduction of code tangling and code scattering Abstraction Obliviousness Expert Development Object Reuse
Join Points Join Point - Point in the base code that aspect code can utilized Examples A method being called A method’s code being run Initialization
Pointcuts User defined join point(s) to utilize aspect code with Aspect. J examples execution(!static * (Class 1 || Class. A). *(. . )); call(void Set*(int)); Explanation
Advice Basically a function before, after, and around key words around has a special proceed() function Has access to some information from base code Function name, parameters, return type, return value
Weaving Static vs dynamic Compile-time vs load- or run-time Invasive vs non-invasive Directly changing base code or not
Applications Logging Coordination Security Mutual Exclusion
Coordination Silent Single Bid Public English Style
Downsides Confusion about it’s role Anti-pattern: Action at a distance
Aspect. J Java-based Pointcuts Can use logical operators Can be named Advices are formatted like java functions
Aspect. J Pointcuts pointcut function. Execution(): execution(!static * (Class 1 || Class. A). *(. . )) Name Join point type Join point specification
Aspect. J Pointcuts Name Shorter than the pointcut itself Can include parameters to capture access to an object pointcut setter(Person p): target(p) && …
Aspect. J Pointcut Types Methods and Constructors call(Signature) / execution(Signature) //before call Person. walk(); //after call Private void walk() { //before execution //TODO: write function body //after execution }
Aspect. J Pointcut Types Fields get(Signature) / set(Signature) E. g. set(int Racer. *) private int id; … //before set id = 42; //after set
Aspect. J Pointcut Types Instanceof checks and context exposure this(type or id) / target(type or id) / args(type or id) E. g. args(newval), target(Racer) Others http: //eclipse. org/aspectj/doc/released/progguide/quick. html#quick-pointcuts
Aspect. J Advices void around(Racer r): critical. Section(r) { int i = (int) r. get. Id(); …proceed(); … } this. Join. Point Can be used to get arguments, signature, target, etc this. Join. Point. get. Args();
Example of Mutual Exclusion Aspect
Questions
References [1] Aspect-oriented software development. In Wikipedia. Retrieved October 20, 2013, from http: //en. wikipedia. org/wiki/Aspectoriented_software_development [2] Rohit Sethi. “Aspect-Oriented Programming and Security”. Retrieved October 28, 2013, from http: //www. symantec. com/connect/articles/aspect-oriented-programming-and-security [3] Fuentes, Lidia; Sánchez, Pablo. “Aspect-Oriented Coordination”. In Science Direct. Retrieved from http: //www. sciencedirect. com/science/article/pii/S 1571066107004926 [4] Aspect Weaver. In Wikipedia. Retrieved October 28, 2013, from http: //en. wikipedia. org/wiki/Aspect_weaver [5] Piveta, Eduardo Kessler; Zancanella, Luiz Carlos. “Aspect Weaving Strategies”. In Journal of Universal Computer Science. Retrieved from http: //citeseerx. ist. psu. edu/viewdoc/download? doi=10. 1. 1. 2. 9460&rep=rep 1&type=pdf [6] The Aspect. J Programming Guide. Retrieved October 28, 2013, from http: //eclipse. org/aspectj/doc/released/progguide/index. html
- Slides: 20