1 / 20

Aspect Oriented Development

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

yasuo
Télécharger la présentation

Aspect Oriented Development

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. Aspect Oriented Development Alex Beatty

  2. Introduction • Purpose • Cross-cutting Concerns • Join Points, Pointcuts, and Advices • Weaving • Invasive vs. Non-Invasive • Static vs. Dynamic

  3. Purpose • What is a cross-cutting concern? • Examples • Reduction of code tangling and code scattering • Abstraction • Obliviousness • Expert Development • Object Reuse

  4. 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

  5. Pointcuts • User defined join point(s) to utilize aspect code with • AspectJ examples • execution(!static * (Class1 || ClassA).*(..)); • call(void Set*(int)); • Explanation

  6. 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

  7. Weaving • Static vs dynamic • Compile-time vs load- or run-time • Invasive vs non-invasive • Directly changing base code or not

  8. Applications Logging Coordination Security Mutual Exclusion

  9. Coordination Silent Single Bid Public English Style

  10. Downsides Confusion about it’s role Anti-pattern: Action at a distance

  11. AspectJ • Java-based • Pointcuts • Can use logical operators • Can be named • Advices are formatted like java functions

  12. AspectJPointcuts pointcutfunctionExecution(): execution(!static * (Class1 || ClassA).*(..)) Name Join point type Join point specification

  13. AspectJPointcuts • Name • Shorter than the pointcut itself • Can include parameters to capture access to an object • pointcut setter(Person p): target(p) && …

  14. AspectJPointcut Types //before call Person.walk(); //after call Private void walk() { //before execution //TODO: write function body //after execution } • Methods and Constructors • call(Signature) / execution(Signature)

  15. AspectJPointcut Types private int id; … //before set id = 42; //after set • Fields • get(Signature) / set(Signature) • E.g. set(int Racer.*)

  16. AspectJPointcut 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

  17. AspectJ Advices void around(Racer r): criticalSection(r) { inti = (int) r.getId(); …proceed(); … } • thisJoinPoint • Can be used to get arguments, signature, target, etc • thisJoinPoint.getArgs();

  18. Example of Mutual Exclusion Aspect

  19. Questions

  20. References [1] Aspect-oriented software development. In Wikipedia. Retrieved October 20, 2013, from http://en.wikipedia.org/wiki/Aspect-oriented_software_development [2] RohitSethi. “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/S1571066107004926 [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=rep1&type=pdf [6] The AspectJ Programming Guide. Retrieved October 28, 2013, from http://eclipse.org/aspectj/doc/released/progguide/index.html

More Related