Download presentation
Presentation is loading. Please wait.
1
Aspect-Oriented Software Development (AOSD) Tutorial #7 Assume – guarantee specifications; EAOP
2
Aspect-Oriented Software Development (236608) 2 Today: Aspects Categories (contd.), LTL properties Assume – guarantee aspects specification Event-based Aspect Oriented Programming Examples
3
Aspect-Oriented Software Development (236608) 3 Example Class: Point - reminder 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 Assume-guarantee spec. 1 Aspect 1: Positive quarter check. After each change in points, check whether they are in the positive quarter of the space pointcut movePoint … //calls to setX(), setY() … pointcut createPoint … //calls to Point(..) after(Point pt, int newArg) returning(): movePoint(pt, newArg) { if( newArg < 0) System.out.println( “…” ); } after(int x, int y) returning(): createPoint(x, y) { if( x < 0 || y < 0) System.out.println( “…” ); }
5
Aspect-Oriented Software Development (236608) 5 Assume-guarantee spec. 1 – contd. Assumption: Guarantee:
6
Aspect-Oriented Software Development (236608) 6 Assume-guarantee spec. 2 Aspect 2: Positive quarter enforce. Make sure all the points are in the positive quarter of the space … void around(Point pt, int newArg): movePoint(pt, newArg) { if( newArg >= 0) proceed(pt, newArg); else System.out.println( “…” ); } Point around(int x, int y) : createPoint(x, y) { if( x < 0) { x=0; System.out.println( “…” );} if( y < 0) { y=0; System.out.println( “…” );} proceed(x,y); }
7
Aspect-Oriented Software Development (236608) 7 Assume-guarantee spec. 2 – contd. Assumption: Guarantee:
8
Aspect-Oriented Software Development (236608) 8 Assume-guarantee spec. 3 Aspect3: Adding names to points; tracing movements private String Point.name = ""; public String Point.getName() {return name;} public void Point.setName(String newName) {name = newName;} … pointcut moved(Point pt): target(pt) && (call(void setX(int)) || call(void setY(int))); after(Point pt) returning: moved (pt) { System.out.println("Point "+pt.getName()+" moved to ("+pt.getX()+","+pt.getY()+")"); }
9
Aspect-Oriented Software Development (236608) 9 Assume-guarantee spec. 3 – contd. Assumption: Guarantee:
10
Aspect-Oriented Software Development (236608) 10 E-Commerce Example - Reminder Aspects: Bingo (half-price for every 1000-th client) Discount (10% discount after accumulated purchase value > 100) Profiling (counts bingos / discounts given) Checkout (abstract, implemented by Bingo and Discount)
11
Aspect-Oriented Software Development (236608) 11 Example – Aspects of Aspects Profiling of discounts is an example of an aspect which is applied to other aspects. Have a look at the definition of the aspect Profiling, an excerpt of which is shown here: while (true) { Event e = nextComputeDiscount(); this.isCrosscutting = true; n++; System.out.println("aspect profile: " + "number of discounts and bingos = " + n); } Profiling BingoDiscount
12
Aspect-Oriented Software Development (236608) 12 Example – Dynamic Instantiation of Aspects and Events While we have already seen examples of dynamic event creation during runtime, and aspect creation at program start time, the Discount aspect provides a more interesting example of dynamic instantiation of aspects. Let's have another look at an excerpt of this aspect:
13
13 Example – Dynamic instantiation of aspects public void definition() { Customer cust = newCustomer(); insert(new Discount()); while (true) { Order o = nextShip(cust); accPurchases += o.total(); System.out.println("aspect discount: accumulated purchases of " + cust + " is " + accPurchases); if (accPurchases > Discount.discountThreshold) { Event e2 = nextCheckout(cust); System.out.print("aspect discount: "); float discount = computeDiscount(Discount.discountRate,cust); Set tmp = new HashSet(); tmp.add(new Product("discount", -discount)); cust.shoppingCart.add(tmp); accPurchases -= Discount.discountThreshold; } In order to express that discounts are applied on a per-customer basis, we use dynamic instantiation of aspects:
14
Aspect-Oriented Software Development (236608) 14 Example – Possible Output Welcome to www.javazon.com... shipping p2 to c2 aspect discount: accumulated purchases of c1 is 40.0 shipping p1 to c1 aspect profile: number of discounts and bingos = 2 apply discount of 10% to c2 aspect profile: number of discounts and bingos = 3 apply discount of 25% (i.e.5.0) to c1...
15
Aspect-Oriented Software Development (236608) 15 Adding Event-based Aspects to Point Which functions should be instrumented? Events in aspect pointcuts: “call” or “return”?
16
Aspect-Oriented Software Development (236608) 16 Aspect Composition Example Aspects on class Point: C: Positive quarter check; E: Positive quarter enforce; N: Name adding and movements tracking
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.