1 Aspect Oriented Programming Programming Languages Seminar Presenter: Barış Aktemur University of Illinois 18 Feb. 2004 Mostly taken from Bedir Tekinerdogan’s.

Slides:



Advertisements
Similar presentations
Ch:8 Design Concepts S.W Design should have following quality attribute: Functionality Usability Reliability Performance Supportability (extensibility,
Advertisements

Programming Paradigms Introduction. 6/15/2005 Copyright 2005, by the authors of these slides, and Ateneo de Manila University. All rights reserved. L1:
A Brief Introduction to Aspect-Oriented Programming Zhenxiao Yang.
Aspect Oriented Programming. AOP Contents 1 Overview 2 Terminology 3 The Problem 4 The Solution 4 Join point models 5 Implementation 6 Terminology Review.
1 JAC : Aspect Oriented Programming in Java An article review by Yuval Nir and Limor Lahiani.
©Ian Sommerville 2006Software Engineering, 8th edition. Chapter 32 Slide 1 Aspect-oriented Software Development.
An Overview of AspectJ Sabine Hauert. Today's Deserts  Whipped introduction served with its three berries syrup  Chocolate history soufflé  Design.
Secure Systems Research Group - FAU Aspect Oriented Programming Carlos Oviedo Secure Systems Research Group.
Aspect-Oriented Programming In Eclipse ® Aspect-Oriented Programming in Eclipse with AspectJ Dr Helen Hawkins and Sian January.
Java.sun.com/javaone/sf | 2004 JavaOne SM Conference | Session BUS JavaOne 2004 What is AOP? Gregor Kiczales AspectMentor.com and University of.
359C 10/1/05 Eric Wohlstadter Introductions –Name –Degree objective/Year –Research Area (or interests) Syllabus Aspect-Oriented Programming –AspectJ –AspectC.
Road Map Introduction to object oriented programming. Classes
ASPECT ORIENTED SOFTWARE DEVELOPMENT Prepared By: Ebru Doğan.
University of British Columbia Software Practices Lab CAS Seminar 06 Fluid AJ - A Simple Fluid AOP Tool Terry Hon Gregor Kiczales.
Aspect-oriented programming Laura Ricci A.A
Software modularity group Gregor Kiczales Professor and NSERC/Xerox/Sierra Systems Software Design Chair University of British Columbia Principal Scientist.
More on AspectJ. aspect MoveTracking { private static boolean _flag = false; public static boolean testAndClear() { boolean result = _flag; _flag = false;
Software Issues Derived from Dr. Fawcett’s Slides Phil Pratt-Szeliga Fall 2009.
Aspect-Oriented Programming with AspectJ™ AspectJ.org Xerox PARC Erik Hilsdale Gregor Kiczales with Bill Griswold, Jim Hugunin, Wes Isberg, Mik Kersten.
C++ fundamentals.
Introduction to Aspect- Oriented Programming CS 3360 Gregor Kiczales, et. al. Getting started with AspectJ, CACM, 44(10):59-65, October Fall 2012.
Introduction to Aspect Oriented Programming Presented By: Kotaiah Choudary. Ravipati M.Tech IInd Year. School of Info. Tech.
Aspect Oriented Programming Razieh Asadi University of Science & Technology Mazandran Babol Aspect Component Based Software Engineering (ACBSE)
Aspect Oriented Programming Scott Nykl CSSE 411 Senior Seminar.
SAMANVITHA RAMAYANAM 18 TH FEBRUARY 2010 CPE 691 LAYERED APPLICATION.
Composing Adaptive Software Authors Philip K. McKinley, Seyed Masoud Sadjadi, Eric P. Kasten, Betty H.C. Cheng Presented by Ana Rodriguez June 21, 2006.
©Ian Sommerville 2006Software Engineering, 8th edition. Chapter 32 Slide 1 Aspect-oriented Software Development 1.
MOTOROLA and the Stylized M Logo are registered in the US Patent & Trademark Office. All other product or service names are the property of their respective.
Aspect Oriented Programming Sumathie Sundaresan CS590 :: Summer 2007 June 30, 2007.
Aspect Oriented Programming Gülşah KARADUMAN.
Copyright 2003 Scott/Jones Publishing Standard Version of Starting Out with C++, 4th Edition Chapter 13 Introduction to Classes.
Kiczales and Mezini - FOAL AOP and Modular Reasoning [ICSE05] Start with first-principles definition of modularity and modular reasoning –localization,
AOSD1 Aspect-Oriented Software Design Karl Lieberherr Theo Skotiniotis.
1 Chapter 8 – Classes and Object: A Deeper Look Outline 1 Introduction 2 Implementing a Time Abstract Data Type with a Class 3 Class Scope 4 Controlling.
AOP-1 Aspect Oriented Programming. AOP-2 Aspects of AOP and Related Tools Limitation of OO Separation of Concerns Aspect Oriented programming AspectJ.
Aspect-Oriented Programming and Modular Reasoning G. KiczalesM. Mezini Presented by Alex Berendeyev.
Features of AOP languages AOP languages have the following main elements: –a join point model (JPM) wrt base PL –a specification language for expressing.
IDENTIFYING SEMANTIC DIFFERENCES IN ASPECTJ PROGRAMS Martin Görg and Jianjun Zhao Computer Science Department, Shanghai Jiao Tong University.
Adaptive Software Kevin Cella Graduate Seminar 02/04/2005.
Inter-Type Declarations in AspectJ Awais Rashid Steffen Zschaler © Awais Rashid, Steffen Zschaler 2009.
Demeter Aspects We study techniques for the emerging area of Aspect-Oriented Software Development and focus on the following areas:  Aspectual Collaborations.
Shanghai Jiao Tong University 上海交通大学软件工程中心 Object Oriented Analysis and Design Aspect-Oriented Software Development (AOSD)
Aspect Oriented Development Alex Beatty.  Purpose  Cross-cutting Concerns  Join Points, Pointcuts, and Advices  Weaving  Invasive vs. Non-Invasive.
Alloy-based Lightweight Verification for Aspect-oriented Architecture Naoyasu Ubayashi(Kyushu Institute of Technology) Yuki Sato(Kyushu Institute of Technology)
问题 Code scattering Blocks of duplicated code Blocks of complementary code, and different modules implementing complementary parts of the concern Code.
Comparison of Different AOP Approaches Presented by: Xiaojing Wang.
aspectj tools new and noteworthy Mik Kersten University of British Columbia Adrian Colyer IBM Hursley OOPSLA, October
AOSD'04, Lancaster, UK 1 Remote Pointcut - A Language Construct for Distributed AOP Muga Nishizawa (Tokyo Tech) Shigeru Chiba (Tokyo Tech) Michiaki Tatsubori.
R R R A Brief Introduction to Aspect-Oriented Programming.
Introduction to Aspect- Oriented Programming CS 3360 Gregor Kiczales, et. al. Getting started with AspectJ, CACM, 44(10):59-65, October Spring 2012.
CSC450 Software Engineering Devon M. Simmonds University of North Carolina, Wilmington 1.
UBC software modularity group 1/14/02 UCSD1 Discussion with Kiczales at UBC Ontology of AOP Ontology is the study of what there is, an inventory of what.
Aspect-Oriented Software Development (AOSD)
AO Mechanisms in Demeter1 Discussion with Gregor Kiczales at UBC Ontology of AOP Ontology is the study of what there is, an inventory of what exists. An.
Talk only to your friends that share the same concerns (Law of Demeter for Concerns) Midterm Review February 2004.
AspectJ Development Tools Mik Kersten University of British Columbia October 28, 2003.
L’origine dei mali: le dipendenze tra componenti Stefano Leli 14° Workshop DotNetMarche Venerdì 16 aprile
Features of AOP languages AOP languages have the following main elements: –a join point model (JPM) wrt base PL –a specification language for expressing.
An Interface Mechanism for Encapsulating Weaving in Class-based AOP
Aspect-Oriented Programming with the Eclipse AspectJ plug-in
Discussion with Gregor Kiczales at UBC
Demeter Aspects Who We Are Aspectual Collaborations
ADAPTIVE PROGRAMMING Sezen ERDEM December 2005.
A Brief Introduction to Aspect-Oriented Programming
AP/DJ AP: a generic technology
Aspect-oriented programming
Aspects at the Design Level
AspectAda Aspect-Oriented Programming for Ada95
Aspect Oriented Software Design
Presentation transcript:

1 Aspect Oriented Programming Programming Languages Seminar Presenter: Barış Aktemur University of Illinois 18 Feb Mostly taken from Bedir Tekinerdogan’s slides

2 Outline Introduction Problems Terminology Aspect-Oriented Programming Languages/Frameworks Compositional Filters AspectJ Hyper/J DemeterJ Conclusions

3 Introduction Evolution of Programming Languages Assembly/Machine Languages Formula Translation Procedural Programming Structured Programming Functional Programming Logic Programming Programming with abstract data types Evolution of Software Design Monolithic ---> Modular

4 Design Principles  Modularity Abstraction Focus only on relevant properties Decomposition Divide software into separately named and addressable modules Encapsulation Group related things together. Information Hiding Hide implementation details from the outside Separation of Concerns Ensure that each module only deals with one concern Low Coupling aim for low coupling among the modules High Cohesion aim for high cohesion within one module

5 Separation of Concerns Cohesion Maximize cohesion within a component i.e. Cohesive component performs only one concern/task required changes can be easily localized and will not propagate Coupling Highly coupled components have many dependencies/interactions Minimize coupling between components reduces complexity of interactions reduces ‘ripple’ effect

6 Advantages of separation of concerns Understandability Maintainability Extensibility Reusability Adaptability Separation of Concerns directly supports quality factors. Lack of Separation of Concerns negatively impacts quality factors.

7 Example - Figure Editor A figure consists of several figure elements. A figure element is either a point or a line. Figures are drawn on Display. A point includes X and Y coordinates. A line is defined as two points.

8 Example - Figure Editor - Design Components are - Cohesive - Loosely Coupled - Have well-defined interfaces (abstraction, encapsulation) Nice Modular Design! Display Figure FigureElement * PointLine getX() getY() getP1 setP1 setX(int) setY(int) setP1(Point) setP2(Point) 2

9 Display Figure FigureElement * PointLine getX() getY() getP1 setP1 DisplayTracking setX(int) setY(int) setP1(Point) setP2(Point) 2 Crosscutting Concern - Example Notify ScreenManager if a figure element moves

10 class Point { void setX(int x) { DisplayTracker.updatePoint(this); this.x = x; } class DisplayTracker { static void updatePoint(Point p) { this.display(p);.... } static void updateLine(Line l) { this.display(l);.... } Display Figure FigureElement * PointLine getX() getY() getP1 setP1 setX(int) setY(int) setP1(Point) setP2(Point) 2 DisplayTracker class Line { void setP1(Point p1 { DisplayTracker.updateLine(this); this.p1 = p1; } Example: Display Tracking Crosscutting Concern

11 Example - Tracing - Design Display Figure FigureElement * PointLine getX() getY() getP1 setP1 setX(int) setY(int) setP1(Point) setP2(Point) 2 Tracer traceEntry traceExit Tracing Trace the execution of all operations...

12 class Point { void setX(int x) { _x = x; } class Tracer { static void traceEntry(String str) { System.out.println(str); } static void traceExit(String str) { System.out.println(str); } } Display Figure FigureElement * PointLine getX() getY() getP1 setP1 setX(int) setY(int) setP1(Point) setP2(Point) 2 Tracer Tracer.traceEntry(“Entry Point.set”); Tracer.traceExit(“Exit Point.set”); class Line { void setP1(Point p1 { _p1 = p1; } Tracer.traceEntry(“Entry Line.set”); Tracer.traceExit(“Exit Line.set”); Tangling Code Example - Tracing Scattered Concern

13 Example – Tracing and Display Tracking Display Figure FigureElement * PointLine getX() getY() getP1 setP1 setX(int) setY(int) setP1(Point) setP2(Point) 2 Tracer trace Tracing Display Tracker

14 Crosscutting, Scattering and Tangling Crosscutting concern that inherently relates to multiple components. results in scattered concern and tangled code non-functional requirements likely to crosscut Scattering Single concern affects multiple modules Tangling multiple concerns are interleaved in a single module

15 Example of crosscutting concerns Synchronization Real-time constraints Error-checking Object interaction constraints Memory management Persistency Security Caching Logging Monitoring Testing Domain specific optimization...

16 Aspect-Oriented Software Development Provides better separation of concerns by explicitly considering crosscutting concerns (as well) Does this by providing explicit abstractions for representing crosscutting concerns, i.e. aspects and composing these into programs, i.e. aspect weaving or aspect composing. As such AOSD improves modularity and supports quality factors such as maintainability adaptability reusability understandability...

17 Basic AOP technologies Composition Filters University of Twente, The Netherlands AspectJ XEROX PARC, US DemeterJ/DJ Northeastern University, US Multi-dimensional separation of Concerns/HyperJ IBM TJ Watson Research Center, US

18 History of AOP languages OO languages MOP (1985) CLOS-MOP Crosscutting aspects (1996) AspectJ (1997) Scripts (Francez 81) Reflection (Smith 81) Sina interface predicates (1988) Composition Filters (1992) AI (semantic networks 79) Composition Filters with superimposition (2001) Law of Demeter (1988) Adaptive programming (1992) AspectJ (2000)

19 AspectJ A general purpose AO programming language just as Java is a general-purpose OO language unlike examples in ECOOP’97 paper domain specific languages for each aspect an integrated extension to Java accepts all java programs as input outputs.class files compatible with any JVM integrated with tools

20 class Line { private Point _p1, _p2; Point getP1() { return _p1; } Point getP2() { return _p2; } void setP1(Point p1) { Tracer.traceEntry(“entry setP1”); _p1 = p1; Tracer.traceExit(“exit setP1”); } void setP2(Point p2) { Tracer.traceEntry(“entry setP2”); _p2 = p2; Tracer.traceExit(“exit setP2”); } class Point { private int _x = 0, _y = 0; int getX() { return _x; } int getY() { return _y; } void setX(int x) { Tracer.traceEntry(“entry setX”); _x = x; Tracer.traceExit(“exit setX”) } void setY(int y) { Tracer.traceEntry(“exit setY”); _y = y; Tracer.traceExit(“exit setY”); } Example – Without AOP Tangling Code Scattered Concern class Tracer { static void traceEntry(String str) { System.out.println(str); } static void traceExit(String str) { System.out.println(str); } }

21 class Line { private Point _p1, _p2; Point getP1() { return _p1; } Point getP2() { return _p2; } void setP1(Point p1) { _p1 = p1; } void setP2(Point p2) { _p2 = p2; } class Point { private int _x = 0, _y = 0; int getX() { return _x; } int getY() { return _y; } void setX(int x) { _x = x; } void setY(int y) { _y = y; } Example – With AOP aspect Tracing { pointcut traced(): call(* Line.* || call(* Point.*); before(): traced() { println(“Entering:” + thisjopinpoint); void println(String str) { } } Aspect is defined in a separate module Crosscutting is localized No scattering; No tangling Improved modularity

22 Aspect Language Elements join point (JP) model certain principled points in program execution such as method calls, field accesses, and object construction means of identifying JPs picking out join points of interest (predicate) pointcuts: set of join points means of specifying behavior at JPs what happens advice declarations

23 Modularizing Crosscutting Joinpoints: any well-defined point of execution in a program such as method calls, field accesses, and object construction Pointcut: predicate on joinpoints selecting a collection of joinpoints. Display Figure FigureElement * PointLine getX() getY() getP1 setP1 setX(int) setY(int) setP1(Point) setP2(Point) 2 Tracer pointcut traced(): call(* Line.*) || call(* Point.*);

24 Joinpoints method call join points when a method is called method reception join points when an object receives a message method execution join points when the body of code for an actual method executes field get joint point when a field is accessed field set joint point when a field is set exception handler execution join point when an exception handler executes object creation join point when an instance of a class is created

25 Some primitive pointcuts call(Signature) picks out method or constructor call based on Signature execution(Signature) picks out a method or constructor execution join point based on Signature get(Signature) picks out a field get join point based on Signature set(Signature) picks out a field set join point based on Signature handles(TypePattern) picks out an exception handler of any of the Throwable types of TypePattern instanceOf(ClassName) picks out join points of currently executing objects of class ClassName within(ClassName) picks out join points that are in code contained in ClassName withinCode(Signature) picks out join points within the member defined by methor or constructor (Signature) cflow(pointcut) picks out all the join points in the control flow of the join points picked out by the pointcut

26 Advice Piece of code that attaches to a pointcut and thus injects behavior at all joinpoints selected by that pointcut. example: before (args): pointcut { Body } where before represents a before advice type (see next slide). Can take parameters with pointcuts

27 Advice Types Advice code executes before, code is injected before the joinpoint before (args): pointcut { Body } after, code is injected after the joinpoint after (args): pointcut { Body } around, code is injected around (in place of) code from joinpoint ReturnType around (args): pointcut { Body } JP Advice JP Advice JP

28 Aspect A modular unit of cross-cutting behavior. Like a class, can have methods, fields, initializers. can be abstract, inherit from classes and abstract aspects and implement interfaces. encapsulates pointcuts and advices can introduce new methods / fields to a class AspectX AspectY classX AspectY AspectX classY x

29 class Line { private Point _p1, _p2; Point getP1() { return _p1; } Point getP2() { return _p2; } void setP1(Point p1) { _p1 = p1; } void setP2(Point p2) { _p2 = p2; } class Point { private int _x = 0, _y = 0; int getX() { return _x; } int getY() { return _y; } void setX(int x) { _x = x; } void setY(int y) { _y = y; } Example - AspectJ aspect Tracing { pointcut traced(): call(* Line.* || call(* Point.*); before(): traced() { println(“Entering:” + thisjopinpoint); after(): traced() { println(“Exit:” + thisjopinpoint); void println(String str) { } } pointcut advice aspect

30 Code Weaving Before compile-time (pre-processor) During compile-time After compile-time At load time At run-time

31 Example - AspectJ aspect MoveTracking { private static boolean _flag = false; public static boolean testAndClear() { boolean result = _flag; _flag = false; return result; } pointcut moves(): receptions(void Line.setP1(Point)) || receptions(void Line.setP2(Point)); static after(): moves() { _flag = true; }

32 DemeterJ / DJ Law Of Demeter Each unit should only have limited knowledge about other units: only about units “closely” related to the current unit. “Each unit should only talk to its friends.” “Don’t talk to strangers.” Goal: Reduce behavioral dependencies between classes. Loose coupling

33 Applying LoD A method must be able to traverse links to obtain its neighbors and must be able to call operations on them. But it should not traverse a second link from the neighbor to a third class. Methods should communicate only with preferred suppliers: immediate parts on this objects passed as arguments to method objects which are directly created in method objects in global variables No other calls allowed ---> Scattering

34 Solution is Adaptive Programming Encapsulate operation into one place thereby avoiding scattering Specify traversal over (graph) structure in a succinct way thereby reducing tangling. Navigation strategy

35 Use of Visitors import edu.neu.ccs.demeter.dj.*; // define strategy String strategy=“from BusRoute through BusStop to Person” class BusRoute { // define class graph static Classgraph cg = new ClassGraph(); int printCountWaitingPersons(){ // traversal/visitor weaving //define visitor Visitor v = new Visitor() public void before(Person host){ r++; … } public void start() { r = 0;} … } cg.traverse(this, strategy, v);... }