20
Aspect Oriented Development Alex Beatty

Aspect Oriented Development Alex Beatty. Purpose Cross-cutting Concerns Join Points, Pointcuts, and Advices Weaving Invasive vs. Non-Invasive

Embed Size (px)

Citation preview

Aspect Oriented Development

Aspect Oriented DevelopmentAlex BeattyPurposeCross-cutting ConcernsJoin Points, Pointcuts, and AdvicesWeavingInvasive vs. Non-InvasiveStatic vs. Dynamic

IntroductionWhat is a cross-cutting concern?ExamplesReduction of code tangling and code scatteringAbstractionObliviousnessExpert DevelopmentObject ReusePurposeJoin Point - Point in the base code that aspect code can utilizedExamplesA method being calledA methods code being runInitialization

Join PointsUser defined join point(s) to utilize aspect code withAspectJ examplesexecution(!static * (Class1 || ClassA).*(..));call(void Set*(int));Explanation

PointcutsBasically a functionbefore, after, and around key wordsaround has a special proceed() functionHas access to some information from base codeFunction name, parameters, return type, return valueAdviceStatic vs dynamicCompile-time vs load- or run-timeInvasive vs non-invasiveDirectly changing base code or notWeavingLoggingCoordinationSecurityMutual Exclusion

ApplicationsCoordination

Silent Single BidPublic English StyleConfusion about its roleAnti-pattern: Action at a distanceDownsidesJava-basedPointcutsCan use logical operatorsCan be namedAdvices are formatted like java functions

AspectJpointcut functionExecution(): execution(!static * (Class1 || ClassA).*(..))NameJoin point typeJoin point specificationAspectJ PointcutsNameShorter than the pointcut itselfCan include parameters to capture access to an objectpointcut setter(Person p): target(p) && AspectJ PointcutsMethods and Constructorscall(Signature) / execution(Signature)

AspectJ Pointcut Types//before callPerson.walk();//after callPrivate void walk(){//before execution//TODO: write function body//after execution}Fieldsget(Signature) / set(Signature)E.g. set(int Racer.*)

AspectJ Pointcut Typesprivate int id; //before setid = 42;//after setInstanceof checks and context exposurethis(type or id) / target(type or id) / args(type or id)E.g. args(newval), target(Racer)

Othershttp://eclipse.org/aspectj/doc/released/progguide/quick.html#quick-pointcutsAspectJ Pointcut Typesvoid around(Racer r): criticalSection(r){ int i = (int) r.getId(); proceed(); }thisJoinPointCan be used to get arguments, signature, target, etcthisJoinPoint.getArgs();AspectJ AdvicesExample of Mutual Exclusion AspectQuestions[1] Aspect-oriented software development. In Wikipedia. Retrieved October 20, 2013, from http://en.wikipedia.org/wiki/Aspect-oriented_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; Snchez, 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

References