Aspect-Oriented Software Development (AOSD) Tutorial #7 Assume – guarantee specifications; EAOP.

Slides:



Advertisements
Similar presentations
Problem Solving 5 Using Java API for Searching and Sorting Applications ICS-201 Introduction to Computing II Semester 071.
Advertisements

C++ Classes & Data Abstraction
Aspect-Oriented Software Development (AOSD) Tutorial #2 AspectJ Basics.
Aspect-Oriented Software Development (AOSD) Tutorial #5 Categories of Aspects – contd.; LTL properties formalization; Assume – guarantee specifications.
Aspect-Oriented Software Development (AOSD) Tutorial #4 Categories of Aspects.
Aspect-Oriented Software Development (AOSD) Tutorial #5 Categories of Aspects – contd.; LTL properties formalization.
Writing methods and Java Statements. Java program import package; // comments and /* … */ and /** javadoc here */ public class Name { // instance variables.
Aspect-Oriented Software Development (AOSD) Tutorial #4 Categories of Aspects.
Aspect-Oriented Software Development (AOSD) Tutorial #8 Composition Filters.
Aspect-Oriented Software Development (AOSD) Tutorial #2 AspectJ Basics.
Copyright 2006 by Pearson Education 1 Building Java Programs Chapter 8: Classes and Objects.
1 Event-based Aspect-Oriented Programming (EAOP) Technion Based on a paper of: R´emi Douence and Mario Sudholt Based on slides by: Omer Ganot.
Information Hiding and Encapsulation
Aspect-Oriented Software Development (AOSD) Additional Tutorial.
Aspect-Oriented Software Development (AOSD) Tutorial #6 Categories of Aspects – contd.; LTL properties formalization; Assume – guarantee specifications.
Aspect-Oriented Software Development (AOSD) Tutorial #3 AspectJ - continued.
1 More on Classes Overview l Overloading l The this keyword l The toString method l The equals method.
Understanding class definitions Looking inside classes.
Aspect-Oriented Software Development (AOSD) Tutorial #7 Assume – guarantee specifications; EAOP.
Aspect-Oriented Software Development (AOSD) Tutorial #3 AspectJ - continued.
March 2005Java Programming1. March 2005Java Programming2 Why Java? Platform independence Object Oriented design Run-time checks (fewer bugs) Exception.
Ranga Rodrigo. Class is central to object oriented programming.
1. 2 using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Decisions { class.
1 Inheritance and Subclasses Instructor: Mainak Chaudhuri
Object Oriented Programming Concepts OOP – reasoning about a program as a set of objects rather than as a set of actions Object – a programming entity.
1 Abstraction  Identify important aspects and ignore the details  Permeates software development programming languages are abstractions built on hardware.
Creative Commons Attribution Non-Commercial Share Alike License sa/3.0/
The Java Programming Language
1 Biggest issue!!! You can’t do questions on this topic correctly unless you draw variables, draw objects when they are created, and draw frames for method.
Aspect Oriented Programming Gülşah KARADUMAN.
Copyright 2008 by Pearson Education Building Java Programs Chapter 8 Lecture 8-3: Encapsulation, this reading: self-checks: #13-17 exercises:
Inheritance - Polymorphism ITI 1121 Nour El Kadri.
Aspect-Oriented Programming and Modular Reasoning G. KiczalesM. Mezini Presented by Alex Berendeyev.
Topic 1 Object Oriented Programming. 1-2 Objectives To review the concepts and terminology of object-oriented programming To discuss some features of.
Alloy-based Lightweight Verification for Aspect-oriented Architecture Naoyasu Ubayashi(Kyushu Institute of Technology) Yuki Sato(Kyushu Institute of Technology)
CreatingClasses-SlideShow-part31 Creating Classes part 3 Barb Ericson Georgia Institute of Technology Dec 2009.
CS305j Introduction to Computing Classes II 1 Topic 24 Classes Part II "Object-oriented programming as it emerged in Simula 67 allows software structure.
Inheritance CSI 1101 Nour El Kadri. OOP  We have seen that object-oriented programming (OOP) helps organizing and maintaining large software systems.
Application development with Java Lecture 21. Inheritance Subclasses Overriding Object class.
Interfaces An interface is like an extreme case of an abstract class – However, an interface is not a class – It is a type that can be satisfied by any.
Print Me Who’s Data? First Executed Name Me My Mistake Q $100 Q $200 Q $300 Q $400 Q $500 Q $100 Q $200 Q $300 Q $400 Q $500 Final Jeopardy.
Iterators ITI 1121 N. El Kadri. Motivation Given a (singly) linked-list implementation of the interface List, defined as follows, public interface List.
1 Classes II Chapter 7 2 Introduction Continued study of –classes –data abstraction Prepare for operator overloading in next chapter Work with strings.
1 Inheritance and Subclasses. 2 Inheritance Often we create very similar classes –Different types of triangles: equilateral, isosceles, etc. –Different.
CSC450 Software Engineering Devon M. Simmonds University of North Carolina, Wilmington 1.
CIS3023: Programming Fundamentals for CIS Majors II Summer 2010 Ganesh Viswanathan Classes and Objects (contd.) Course Lecture Slides 19 May 2010.
Design Patterns. Outline Purpose Purpose Useful Definitions Useful Definitions Pattern Overview Pattern Overview.
CS100Lecture 61 Announcements Homework P1 due on Thursday Homework P2 handed out.
Section 2.2 The StringLog ADT Specification. 2.2 The StringLog ADT Specification The primary responsibility of the StringLog ADT is to remember all the.
Classes and Objects Introduced
Sixth Lecture ArrayList Abstract Class and Interface
An Interface Mechanism for Encapsulating Weaving in Class-based AOP
Chapter 4 Repetition Statements (loops)
Inheritance ITI1121 Nour El Kadri.
The hashCode method.
UML Class Diagram: class Rectangle
Prof. Neary Adapted from slides by Dr. Katherine Gibson
Java Programming with BlueJ
Java Programming Language
Object initialization: constructors
Introduction to Behavioral Patterns (2)
CLASS DEFINITION (FIELDS)
Class Everything if Java is in a class. The class has a constructor that creates the object. public class ClassName private Field data (instance variables)
CSE 142 Lecture Notes Defining New Types of Objects, cont'd.
Building Java Programs
Event-based Aspect-Oriented Programming (EAOP)
Previous Lecture: Today’s Lecture: Reading (JV):
Chapter 5 Classes.
Building Java Programs
Presentation transcript:

Aspect-Oriented Software Development (AOSD) Tutorial #7 Assume – guarantee specifications; EAOP

Aspect-Oriented Software Development (236608) 2 Today: Aspects Categories (contd.), LTL properties Assume – guarantee aspects specification Event-based Aspect Oriented Programming Examples

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; } }

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( “…” ); }

Aspect-Oriented Software Development (236608) 5 Assume-guarantee spec. 1 – contd. Assumption: The coordinates of a point can not be changed without calling the constructor or the setX(), setY() functions Guarantee: Whenever a point appears outside the positive quarter of the space, a warning message is printed

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); }

Aspect-Oriented Software Development (236608) 7 Assume-guarantee spec. 2 – contd. Assumption: The coordinates of a point can not be changed without calling the constructor or the setX(), setY() functions Guarantee: Points never appear outside the positive quarter of the space

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()+")"); }

Aspect-Oriented Software Development (236608) 9 Assume-guarantee spec. 3 – contd. Assumption: The coordinates of an existing point can not be changed without calling the setX(), setY() functions Class Point has no “name” field and no getName(), setName(String...) functions Guarantee: Point has the “name” field and getName(), setName(String...) functions Each change of existing points coordinates is reported to the user

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 > 30) Profiling (counts bingos / discounts given) Checkout (abstract, implemented by Bingo and Discount)

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); } In the loop, events of calls to method computeDiscount are counted, a method which is defined in the abstract aspect Checkout and inherited by the Bingo and Discount aspects. Profiling BingoDiscount Event nextComputeDiscount() { boolean ok = false; Event e = null; while (!ok) { e = nextEvent(); ok = (e instanceof MethodCall) && ((MethodCall)e).method.getName().equals("computeDiscount"); } this.isCrosscutting = true; return e; } where should computeDiscount(..) be defined? meaning: the aspect declares that is has been applied to the current event

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 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: We wait for the next customer creation, Dynamically create a new instance of the discount aspect And insert it into the tree representing the collection of aspects associated to the monitor This new instance is then ready to manage the new customer We have already seen event instantiation

Aspect-Oriented Software Development (236608) 14 Example – Possible Output Welcome to 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... This demonstrates: The different discounts crosscut the execution of the base program. The profiling aspect applies to the discounting aspects. The profiling action is performed before discounting. Discount before profiling? Or profiling before discount?

Aspect-Oriented Software Development (236608) 15 Adding Event-based Aspects to Point Which functions should be instrumented? setX(..), setY(..), Point(..) Events in aspect pointcuts: “call” or “return”? Positive quarter check: return of SetX, SetY, Point Positive quarter enforce: call and return of SetX, SetY, Point Name adding and movements tracking: return of SetX, SetY; call and return of Point

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 Seq N Cond C E_c Seq E_m