Presentation is loading. Please wait.

Presentation is loading. Please wait.

Aspect-Oriented Software Development (AOSD) Tutorial #2 AspectJ Basics.

Similar presentations


Presentation on theme: "Aspect-Oriented Software Development (AOSD) Tutorial #2 AspectJ Basics."— Presentation transcript:

1 Aspect-Oriented Software Development (AOSD) Tutorial #2 AspectJ Basics

2 Aspect-Oriented Software Development (236608) 2 Today: Getting started with AspectJ Advice types Pointcuts –Primitive pointcuts –Pointcuts composition Examples English – AspectJ phrase book (selected entries)

3 Aspect-Oriented Software Development (236608) 3 Example Class: Point class Point { private int x, y; public Point(int x, int y) { this.x = x; this.y = y; } public void setX(int x) { this.x = x; } public void setY(int y) { this.y = y; } public void MoveTo(Point p) {setX(p.x); setY(p.y); } public int getX() { return x; } public int getY() { return y; } }

4 Aspect-Oriented Software Development (236608) 4 English – AspectJ Phrase Book (1) Pointcut: all the calls to the “getters” of Point A short way to say the same: Is this the same?

5 Aspect-Oriented Software Development (236608) 5 English – AspectJ Phrase Book (2) What does this mean? pointcut questionPointcut(Point p1, Point p2): (target(p1) && call(void getX(int))) || (target(p2) && call(void getY(int)));

6 Aspect-Oriented Software Development (236608) 6 Task 1: Positive Quarter Check Task1: After each change in our points, check whether they are in the positive quarter of the space “Positive quarter” means … ? When is the aspect called? (pointcut) - What should the aspect do? (advice) -

7 Aspect-Oriented Software Development (236608) 7 Task 1 – contd.: Pointcut = ? In words: Where in the code? In AspectJ:

8 Aspect-Oriented Software Development (236608) 8 Task 1 – contd.: Pointcut = ? Parameters? Pointcut as a whole, in AspectJ:

9 Aspect-Oriented Software Development (236608) 9 Task1(contd.) Alternative pointcuts?

10 Aspect-Oriented Software Development (236608) 10 Task 1 – contd.: Advice = ? Advice type: Advice parameters:

11 Aspect-Oriented Software Development (236608) 11 Task 1: Advice = ? (In AspectJ)

12 Aspect-Oriented Software Development (236608) 12 Task 2: Positive Quarter Alert Task2: Alert the user before each change that will result in points out of the positive quarter of the space Pointcut = ?

13 Aspect-Oriented Software Development (236608) 13 Task 2 – contd. Advice = ?

14 Aspect-Oriented Software Development (236608) 14 Task 3: Enforce Positive Quarter Task3: Make sure that all our points are in the positive quarter of the space Pointcut = ?

15 Aspect-Oriented Software Development (236608) 15 Task 3 – contd. Advice = ?

16 Aspect-Oriented Software Development (236608) 16 Call vs. Execute – contd. call(void m()) && withincode(void m()) = ? execution(void m()) && withincode(void m()) = ? Enclosing code at a call join-point = ? Enclosing code at an execution join point = ?

17 Aspect-Oriented Software Development (236608) 17 Task 4: Greeting before printing Public class Test { public static void main(String[] args) { foo(); } static void foo () { goo(); } static void goo () { System.out.println( “ message from goo ” ); } Task: Before each printing operation, print a greeting message

18 Aspect-Oriented Software Development (236608) 18 English – AspectJ Phrase Book (3) “All the exceptions thrown by foo()” “All the exceptions thrown while foo() is executed:”

19 Aspect-Oriented Software Development (236608) 19 English – AspectJ Phrase Book (4) “All the exceptions thrown by functions of class Test” What is the relationship between: (1) pointcut except1(): cflow(call(void Test.goo())); (2) pointcut except2(): cflowbelow(call(void Test.foo()));

20 Aspect-Oriented Software Development (236608) 20 Task 4: Proposed solution-1

21 Aspect-Oriented Software Development (236608) 21 Task 4: Proposed solution-2

22 Aspect-Oriented Software Development (236608) 22 Cflow Pointcuts Combination P Q cflow(P) cflow(Q)cflow(P) && cflow(Q) P && Q cflow(P && Q)

23 Aspect-Oriented Software Development (236608) 23 More details… For more details please see the AspectJ Programming Guide, at: http://www.eclipse.org/aspectj/doc/released/ progguide/index.html To be continued at the next tutorial…


Download ppt "Aspect-Oriented Software Development (AOSD) Tutorial #2 AspectJ Basics."

Similar presentations


Ads by Google