DOC PREVIEW
Penn CIT 597 - Aspect Oriented Programming

This preview shows page 1-2-3-27-28-29 out of 29 pages.

Save
View full document
View full document
Premium Document
Do you want full access? Go Premium and unlock all 29 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 29 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 29 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 29 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 29 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 29 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 29 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

Aspect-Oriented ProgrammingProgramming paradigmsThe problemExampleConsequences of crosscutting codeAspectJTMTerminologyThe Figure Element exampleExample IJoin pointsPointcutsExample pointcut designators IExample pointcut designators IIPointcut designator wildcardsPointcut designators based on typesPointcut designator compositionPointcut designators based on modifiersExample I, repeatedKinds of adviceExample II, with parametersIntroductionExample introductionApproximate syntaxExample aspect IExample aspect IISimple tracingChecking pre- and post-conditionsConcluding remarksThe EndJan 14, 2019Aspect-Oriented Programming2Programming paradigmsProcedural programmingExecuting a set of commands in a given sequenceFortran, C, Cobol, PascalFunctional programmingEvaluating a function defined in terms of other functionsLisp, ML, OCamlLogic programmingProving a theorem by finding values for the free variablesPrologObject-oriented programming (OOP)Organizing a set of objects, each with its own set of responsibilitiesSmalltalk, Java, C#, C++ (to some extent), Python, RubyAspect-oriented programming (AOP)Executing code whenever a program shows certain behaviorsAspectJ (a Java extension)Does not replace O-O programming, but rather complements it3The problemSome programming tasks cannot be neatly encapsulated in objects, but must be scattered throughout the codeExamples:Logging (tracking program behavior to a file)Profiling (determining where a program spends its time)Tracing (determining what methods are called when)Session tracking, session expirationSpecial security managementThe result is crosscutting code--the necessary code “cuts across” many different classes and methods4Exampleclass Fraction { int numerator; int denominator; ... public Fraction multiply(Fraction that) { traceEnter("multiply", new Object[] {that}); Fraction result = new Fraction( this.numerator * that.numerator, this.denominator * that.denominator); result = result.reduceToLowestTerms(); traceExit("multiply", result); return result; } ...}Now imagine similar code in every method you might want to trace5Consequences of crosscutting codeRedundant codeSame fragment of code in many places (violates DRY)Difficult to reason aboutNon-explicit structureThe big picture of the tangling isn’t clearDifficult to changeHave to find all the code involved......and be sure to change it consistently...and be sure not to break it by accidentInefficient when crosscutting code is not neededAdapted from:www.parc.xerox.com/research/csl/projects/ aspectj/downloads/PARC-Workshop-2002.ppt6AspectJTMAspectJ is a small, well-integrated extension to JavaBased on the 1997 PhD thesis by Christina Lopes, A Language Framework for Distributed ProgrammingAspectJ modularizes crosscutting concernsThat is, code for one aspect of the program (such as tracing) is collected together in one placeThe AspectJ compiler is free and open sourceAspectJ works with several IDEs, including EclipseBest online writeup: http://www.eclipse.org/aspectj/doc/released/progguide/starting-aspectj.htmlParts of this lecture were taken from the above paper7TerminologyA join point is a well-defined point in the program flowA pointcut is a group of join pointsAdvice is code that is executed at a pointcutIntroduction modifies the members of a class and the relationships between classesAn aspect is a module for handling crosscutting concernsAspects are defined in terms of pointcuts, advice, and introductionAspects are reusable and inheritableEach of these terms will be discussed in greater detail8The Figure Element example9Example IA pointcut named move that chooses various method calls:pointcut move(): call(void FigureElement.setXY(int,int)) || call(void Point.setX(int)) || call(void Point.setY(int)) || call(void Line.setP1(Point)) || call(void Line.setP2(Point));Advice (code) that runs before the move pointcut:before(): move() { System.out.println("About to move");}Advice that runs after the move pointcut:after(): move() { System.out.println("Just successfully moved");}10Join pointsA join point is a well-defined point in the program flowWe want to execute some code (“advice”) each time a join point is reachedWe do not want to clutter up the code with explicit indicators saying “This is a join point”AspectJ provides a syntax for indicating these join points “from outside” the actual codeA join point is a point in the program flow “where something happens”Examples:When a method is calledWhen an exception is thrownWhen a variable is accessed11PointcutsPointcut definitions consist of a left-hand side and a right-hand side, separated by a colonThe left-hand side consists of the pointcut name and the pointcut parameters (i.e. the data available when the events happen)The right-hand side consists of the pointcut itselfExample pointcut:pointcut setter(): call(void setX(int));The name of this pointcut is setterThe pointcut has no parametersThe pointcut itself is call(void setX(int))The pointcut refers to any time the void setX(int) method is called12Example pointcut designators IWhen a particular method body executes:execution(void Point.setX(int)) When a method is called:call(void Point.setX(int)) When an exception handler executes:handler(ArrayOutOfBoundsException) When the object currently executing (i.e. this) is of type SomeType: this(SomeType)13Example pointcut designators IIWhen the target object is of type SomeType target(SomeType) When the executing code belongs to class MyClass within(MyClass) When the join point is in the control flow of a call to a Test's no-argument main methodcflow(call(void Test.main()))14Pointcut designator wildcardsIt is possible to use wildcards to declare pointcuts:execution(* *(..)) Chooses the execution of any method regardless of return or parameter types call(* set(..)) Chooses the call to any method named set regardless of return or parameter typeIn case of overloading there may be more than one such set method; this pointcut picks out calls to all of them15Pointcut designators based on typesYou can select elements based on types. For


View Full Document

Penn CIT 597 - Aspect Oriented Programming

Documents in this Course
DOM

DOM

21 pages

More DOM

More DOM

11 pages

Rails

Rails

33 pages

DOM

DOM

21 pages

RELAX NG

RELAX NG

31 pages

RELAX NG

RELAX NG

31 pages

RELAX NG

RELAX NG

31 pages

RELAX NG

RELAX NG

31 pages

Rake

Rake

12 pages

Ruby

Ruby

58 pages

DOM

DOM

21 pages

Tomcat

Tomcat

16 pages

DOM

DOM

21 pages

Servlets

Servlets

29 pages

Logging

Logging

17 pages

Html

Html

27 pages

DOM

DOM

22 pages

RELAX NG

RELAX NG

30 pages

Servlets

Servlets

28 pages

XHTML

XHTML

13 pages

DOM

DOM

21 pages

DOM

DOM

21 pages

Servlets

Servlets

26 pages

More CSS

More CSS

18 pages

Servlets

Servlets

29 pages

Logging

Logging

17 pages

Load more
Download Aspect Oriented Programming
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Aspect Oriented Programming and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Aspect Oriented Programming 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?