Introduction to Aspect-Oriented Programming

Size: px
Start display at page:

Download "Introduction to Aspect-Oriented Programming"

Transcription

1 Introduction to Aspect-Oriented Programming Martin Giese Chalmers University of Technology Göteborg, Sweden AOP Course 2003 p.1/44

2 AspectJ Quick Tour AOP Course 2003 p.2/44

3 Reminder: Join Points A join point is a well-defined point in the execution of a program. Examples: a method/constructor call execution of a method/constructor implementation read/write access to a field. Program flow can enter and leave a join point. AOP Course 2003 p.3/44

4 Reminder: Pointcuts A pointcut is the static designation of some set of join points for every execution of the program. Examples: all calls to public methods of the Point class every execution of a constructor with one int argument every write access to a public field. AOP Course 2003 p.4/44

5 Code Example: Figure Editor Figure +makepoint(..) +makeline(..) * FigureElement +moveby(int,int) Display +update() Point +getx() +gety() +setx(int) +sety(int) +moveby(int,int) 2 Line +getp1() +getp2() +setp1(point) +setp2(point) +moveby(int,int) AOP Course 2003 p.5/44

6 Code Example (cont.) class Line implements FigureElement { private Point p1, p2; Point getp1() { return p1; } Point getp2() { return p2; } void setp1(point p1) { this.p1 = p1; } void setp2(point p2) { this.p2 = p2; } void moveby(int dx, int dy) { p1.moveby(dx,dy); p2.moveby(dx,dy); } } class Point implements FigureElement { private int x = 0, y = 0; int getx() { return x; } int gety() { return y; } void setx(int x) { this.x = x; } void sety(int y) { this.y = y; } void moveby(int dx, int dy) { x += dx; y += dy; } } AOP Course 2003 p.6/44

7 Pointcuts in AspectJ Primitive pointcuts: call(void Point.setX(int)) each join point that is a call to a method that has the signature void Point.setX(int) Also for interface signatures: call(void FigureElement.moveBy(int,int)) Each call to the moveby(int,int) method in a class that implements FigureElement More later... AOP Course 2003 p.7/44

8 Composition of Pointcuts Pointcuts can be joined using boolean operators &&,,!. call(void Point.setX(int)) call(void Point.setY(int)) calls to the setx and sety methods of Point. Question: what does this select? call(void Line.setP1(Point)) && call(void Line.setP2(Point)) AOP Course 2003 p.8/44

9 Join points from many types Join points from different types possible: call(void FigureElement.moveBy(int,int)) call(void Point.setX(int)) call(void Point.setY(int)) call(void Line.setP1(Point)) call(void Line.setP2(Point)) Any call to a state-changing method in the given FigureElement classes AOP Course 2003 p.9/44

10 Named Pointcuts Pointcuts can be declared to give them a name: pointcut statechange() : call(void FigureElement.moveBy(int,int)) call(void Point.setX(int)) call(void Point.setY(int)) call(void Line.setP1(Point)) call(void Line.setP2(Point)); Analogous to method declaration or typedef in C. After declaration, statechange() can be used wherever a pointcut is expected. AOP Course 2003 p.10/44

11 Wildcards Method signatures can contain wildcards: call(void java.io.printstream.println(*)) any PrintStream method named println returning void and taking exactly one argument of any type. call(public * Figure.*(..)) any public method in Figure. call(public * Line.set*(..)) any method in Line with a name starting with set. AOP Course 2003 p.11/44

12 Example The pointcut from before, using wildcards: pointcut statechange() : call(void FigureElement.moveBy(int,int)) call(* Point.set*(*)) call(* Line.set*(*)); AOP Course 2003 p.12/44

13 Advice in AspectJ Advice can be attached to join points: before(): statechange() { System.out.println("about to change state"); } after() returning: statechange() { } System.out.println("just successfully changed state"); AOP Course 2003 p.13/44

14 Aspects in AspectJ public aspect DisplayUpdating { pointcut statechange() : call(void FigureElement.moveBy(int,int)) call(* Point.set*(*)) call(* Line.set*(*)); after() returning : statechange() { Display.update(); } } After every state changing call, update the display. AOP Course 2003 p.14/44

15 Compilation No partial compilation in AspectJ! Always provide all class and aspect source files. ajc Main.java Display.java Figure.java FigureElement.java \ Line.java Point.java DisplayUpdating.java or ajc -argfile files.lst run using: java Main AOP Course 2003 p.15/44

16 AspectJ Details AOP Course 2003 p.16/44

17 Type Patterns Used to denote a set of types. int Line * java.util.map* java..*factory* java.io.outputstream+ Foo+ &&!Foo Foo+ &&!(java..bar*[]) AOP Course 2003 p.17/44

18 Method Patterns Used to denote a set of methods in one or more classes. Method declaration: public final void write(int x) throws IOException Method pattern: public final void Writer.write(int) throws IOException Wildcards possible everywhere... void *.write(int) void Foo+.set*(int) AOP Course 2003 p.18/44

19 Method Patterns (cont.) * Foo.write(*) * Foo.write(..) * Foo.write(..,int) * *.*(..) public Foo.*(..)!public *.*(..) * *.*(..) throws java.io.ioexception * *.*(..) throws!java.io.ioexception * *.*(..) throws (!java.io.ioexception) AOP Course 2003 p.19/44

20 Constructor and Field Patterns Select a set of constructors: Like method patterns, with name new and no return type: Line.new(int) public *.new(..). Field Patterns: int Line.x public!final * FigureElement+.*. AOP Course 2003 p.20/44

21 Primitive Pointcuts call(methodpattern) call(constructorpattern) execution(methodpattern) execution(constructorpattern) get(fieldpattern) set(fieldpattern) handler(typepattern) AOP Course 2003 p.21/44

22 Restricting the Scope Static Scope: within(typepattern) withincode(methodpattern) withincode(constructorpattern) Dynamic Scope: cflow(pointcut) cflowbelow(pointcut) AOP Course 2003 p.22/44

23 Examples Match constructor calls from outside factory: call(figureelement+.new()) &&!within(figure) Match state changing calls that are not due to other state changing calls: statechange() &&!cflowbelow(statechange()) Match state changes that are not due to some method in Figure: statechange() &&!cflow(execution(* Figure.*(..))) AOP Course 2003 p.23/44

24 Example: cflow caller point 1 moveby a line moveby point 2 moveby AOP Course 2003 p.24/44

25 Pointcuts with Parameters One often needs information about the context of a join point. use pointcuts with parameters. Example: pointcut statechange(figureelement figelt) : target(figelt) && ( call(void FigureElement.moveBy(int,int)) call(* Point.set*(*)) call(* Line.set*(*)) ); after(figureelement fe) : statechange(fe) {...} AOP Course 2003 p.25/44

26 Parameters in pointcut declaration pointcut statechange(figureelement figelt) : target(figelt) && ( call(void FigureElement.moveBy(int,int)) call(* Point.set*(*)) call(* Line.set*(*)) ); figelt declared in header, together with name. bound by the target pointcut target alone matches any non-static call, field access, etc. if the target type matches the declared parameter type. AOP Course 2003 p.26/44

27 Parameters in advice declaration after(figureelement fe) : statechange(fe) {... code can use fe... } after(figureelement fe) : target(fe) &&... {... code can use fe... } fe declared in header bound by the pointcut values move from right to left over the colon. AOP Course 2003 p.27/44

28 Some more Pointcuts target(id) target(type) this(type or Id) args(type or Id... ) if(boolean expression) AOP Course 2003 p.28/44

29 Example: Diagonal Moves Define a pointcut for moves with equal dx and dy. pointcut diagmove() : call(void FigureElement.moveBy(int,int)) && args(dx,dx); AOP Course 2003 p.29/44

30 Example: Diagonal Moves Define a pointcut for moves with equal dx and dy. pointcut diagmove(int dx) : call(void FigureElement.moveBy(int,int)) && args(dx,dx); AOP Course 2003 p.30/44

31 Example: Diagonal Moves Define a pointcut for moves with equal dx and dy. pointcut diagmove(int dx,int dy) : call(void FigureElement.moveBy(int,int)) && args(dx,dy) && if(dx==dy); AOP Course 2003 p.31/44

32 Example: Diagonal Moves Define a pointcut for moves with equal dx and dy. pointcut diaghelp(int dx,int dy) : call(void FigureElement.moveBy(int,int)) && args(dx,dy) && if(dx==dy); pointcut diagmove(int dxy) : diaghelp(dxy,int); AOP Course 2003 p.32/44

33 About Conditionals AspectJ specification: The boolean expression used can only access static members, variables exposed by the enclosing pointcut or advice, (and thisjoinpoint forms). But still... static methods may be called, which may have side effects! left to right evaluation order of pointcuts. Exercise: What about join points of static functions called in if? AOP Course 2003 p.33/44

34 Advice in AspectJ Before advice: before(formal parameters) : Pointcut {... advice body... } The advice body gets executed every time just before the program flow enters a join point matched by the pointcut. The formal parameters receive values from the pointcut. AOP Course 2003 p.34/44

35 After Advice After advice: after(formal parameters) returning : Pointcut {...} The advice body gets executed every time just after the program flow exits a join point matched by the pointcut by returning normally. Capture return value: after(...) returning (int ret): Pointcut {...} AOP Course 2003 p.35/44

36 After Advice (cont.) Advice after throwing an exception: after(formal parameters) throwing : Pointcut {...} Capture thrown exception: after(...) throwing (Exception e): Pointcut {...} Match normal and abrupt return: after(...) : Pointcut {...} AOP Course 2003 p.36/44

37 Around Advice Run advice instead of original code: Type around(... ) :... {... proceed(... );... } run advice body instead of original call, field access, method body, etc. use proceed to use the original join point, if needed. AOP Course 2003 p.37/44

38 Example: Caching Cache values from an expensive function call. int around(int x) : call(int Expensive.f(int)) && args(x) { if (cache.contains(x)) { return cache.get(x); } else { int result = proceed(x); cache.put(x,result); return result; } } AOP Course 2003 p.38/44

39 thisjoinpoint For tracing or logging join points, matched methods might have very different signatures. difficult to pass all useful information through parameters. Special variable thisjoinpoint available in advice. thisjoinpoint.tostring() thisjoinpoint.gettarget() thisjoinpoint.getargs() thisjoinpoint object expensive to construct. thisjoinpointstaticpart is statically constructed. AOP Course 2003 p.39/44

40 Aspects in AspectJ Similar to class declarations, but Can also contain pointcut and advice declarations, System and not user controls instantiation, (An aspect gets instantiated the first time, some advice in it needs to be executed.) Aspects can extend only abstract aspects, (They can extend classes and implement interfaces) Classes cannot extend aspects. AOP Course 2003 p.40/44

41 Caching Aspect package se.chalmers.cs.caching; import se.chalmers.cs.calculations.expensive; public aspect CacheExpensiveFunction { private IntegerCache cache = new IntegerCache(); } int around(int x) : call(int Expensive.f(int)) && args(x) { if (cache.contains(x)) { return cache.get(x); } else { int result = proceed(x); cache.put(x,result); return result; } } AOP Course 2003 p.41/44

42 Tracing Aspect (first try) package tracing; public aspect TraceAllCalls { pointcut pointstotrace() : call(* *.*(..)) ; before() : pointstotrace() { } System.err.println("Enter " + thisjoinpoint); } after() : pointstotrace() { System.err.println("Exit } " + thisjoinpoint); AOP Course 2003 p.42/44

43 Tracing Aspect package tracing; public aspect TraceAllCalls { pointcut pointstotrace() : call(* *.*(..)) &&!within(traceallcalls); before() : pointstotrace() { } System.err.println("Enter " + thisjoinpoint); } after() : pointstotrace() { System.err.println("Exit } " + thisjoinpoint); AOP Course 2003 p.43/44

44 Conclusion You should now know about... AspectJ s main kinds of primitive pointcuts named pointcuts pointcuts with parameters different kinds of advice thisjoinpoint syntax for aspects Tomorrow, you will learn about inter-type declarations and other advanced stuff. AOP Course 2003 p.44/44

Motivation. Ability is what you're capable of doing. Motivation determines what you do. Attitude determines how well you do it.

Motivation. Ability is what you're capable of doing. Motivation determines what you do. Attitude determines how well you do it. Aspects in AspectJ Motivation Aspect Oriented Programming: a brief introduction to terminology Installation Experimentation AspectJ some details AspectJ things you should know about but we dont have time

More information

Aspects in AspectJ. October 2013 CSC5021: AspectJ (J P Gibson) 1

Aspects in AspectJ. October 2013 CSC5021: AspectJ (J P Gibson) 1 Aspects in AspectJ Motivation Aspect Oriented Programming: a brief introduction to terminology Installation Experimentation AspectJ some details AspectJ thingsyoushouldknow about but wedont have time to

More information

An AspectJ-enabled Eclipse Runtime Engine - Demonstration at AOSD 04 - Martin Lippert

An AspectJ-enabled Eclipse Runtime Engine - Demonstration at AOSD 04 - Martin Lippert An AspectJ-enabled Eclipse Runtime Engine - Demonstration at AOSD 04 - Martin Lippert lippert@acm.org www.martinlippert.com Motivation Use Eclipse 3.0 RCP to develop enterprise applications Use AspectJ

More information

with Aspect/J 24) Aspect-Oriented Programming Literature [KLM+97] G. Kiczales, J. Lamping, A. Mendhekar, C. Maeda, C.

with Aspect/J 24) Aspect-Oriented Programming Literature [KLM+97] G. Kiczales, J. Lamping, A. Mendhekar, C. Maeda, C. 24) Aspect-Oriented Programming with Aspect/J Prof. Dr. Uwe Aßmann Florian Heidenreich Technische Universität Dresden Institut für Software- und Multimediatechnik http//st.inf.tu-dresden.de Version 11-0.1,

More information

with Aspect/J 44. Aspect-Oriented Programming Literature [KLM+97] G. Kiczales, J. Lamping, A. Mendhekar, C. Maeda, C.

with Aspect/J 44. Aspect-Oriented Programming Literature [KLM+97] G. Kiczales, J. Lamping, A. Mendhekar, C. Maeda, C. 44. Aspect-Oriented Programming with Aspect/J Prof. Dr. Uwe Aßmann Technische Universität Dresden Institut für Software- und Multimediatechnik http://st.inf.tu-dresden.de Version 14-0.9, June 14, 2014

More information

GETTING STARTED WITH ASPECTJ

GETTING STARTED WITH ASPECTJ a GETTING STARTED WITH ASPECTJ An aspect-oriented extension to Java enables plug-and-play implementations of crosscutting. Many software developers are attracted to the idea of AOP they recognize the concept

More information

Aspect-Oriented Programming and AspectJ

Aspect-Oriented Programming and AspectJ What is Aspect-Oriented Programming? Many possible answers: a fad Aspect-Oriented Programming and AspectJ Aspect-oriented programming is a common buzzword lately Papers from ECOOP 1997 (early overview

More information

Aspect Oriented Programming

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

More information

Evolving mutation from objects to the cloud

Evolving mutation from objects to the cloud Evolving mutation from objects to the cloud MUTATION workshop, Berlin, March 2011 Benoit Baudry 1 Outline A perspective on testing in evolving software construction paradigms A methodological pattern:

More information

A Brief Introduction to Aspect-Oriented Programming" Historical View Of Languages"

A Brief Introduction to Aspect-Oriented Programming Historical View Of Languages A Brief Introduction to Aspect-Oriented Programming" Historical View Of Languages" Procedural language" Functional language" Object-Oriented language" 1 Acknowledgements" Zhenxiao Yang" Gregor Kiczales"

More information

A Brief Introduction to Aspect-Oriented Programming. Historical View Of Languages. Procedural language Functional language Object-Oriented language

A Brief Introduction to Aspect-Oriented Programming. Historical View Of Languages. Procedural language Functional language Object-Oriented language A Brief Introduction to Aspect-Oriented Programming Historical View Of Languages Procedural language Functional language Object-Oriented language 1 Acknowledgements Zhenxiao Yang Gregor Kiczales Procedural

More information

The AspectJTM Programming Guide

The AspectJTM Programming Guide Table of Contents The AspectJTM Programming Guide...1 the AspectJ Team...1 Preface...3 Chapter 1. Getting Started with AspectJ...3 Introduction...4 AspectJ Semantics...5 The Dynamic Join Point Model...6

More information

An Aspect Refactoring Tool for The Observer Pattern

An Aspect Refactoring Tool for The Observer Pattern An Aspect Refactoring Tool for The Observer Pattern A Thesis Submitted to the College of Graduate Studies and Research in Partial Fulfillment of the Requirements for the degree of MSc in the Department

More information

Meta-Program and Meta-Programming

Meta-Program and Meta-Programming Meta-Program and Meta-Programming What is a Meta-Programming? The creation of procedures and programs that automatically construct the definitions of other procedures and programs. First example the Turing

More information

Aspect-Oriented Programming and the AspectJ

Aspect-Oriented Programming and the AspectJ Aspect-Oriented Programming and the AspectJ Tamás Kozsik (kto@elte.hu, http://kto.web.elte.hu/) Dept. Programming Languages and Compilers Eötvös Loránd University, Budapest (Hungary) April 11-15. 2005.

More information

Aspect-Oriented Programming

Aspect-Oriented Programming Aspect-Oriented Programming Harald Gall University of Zurich seal.ifi.uzh.ch/ase Source: http://www.eclipse.org/aspectj/doc/released/progguide/starting-aspectj.html Programming paradigms Procedural programming

More information

Using Aspect-Oriented Programming to extend Protégé. Henrik Eriksson Linköping University

Using Aspect-Oriented Programming to extend Protégé. Henrik Eriksson Linköping University Using Aspect-Oriented Programming to extend Protégé Henrik Eriksson Linköping University Questions about MOP and Protégé Original goal: Extending the JessTab plug-in What is the class precedence in Protégé?

More information

Introduction to Aspect-Oriented Programming

Introduction to Aspect-Oriented Programming Introduction to Aspect-Oriented Programming Martin Giese Chalmers University of Technology Göteborg, Sweden AOP Course 2003 p.1/33 AspectJ Idioms and Patterns AOP Course 2003 p.2/33 Sources These idioms

More information

Aspect-oriented programming with AspectJ

Aspect-oriented programming with AspectJ www.ijcsi.org 212 Aspect-oriented programming with AspectJ Daniela Gotseva 1 and Mario Pavlov 2 1 Computer Systems Department, Technical University of Sofia Sofia, Bulgaria 2 Computer Systems Department,

More information

So, What is an Aspect?

So, What is an Aspect? Introduction to AspectJ Aspect-oriented paradigm AspectJ constructs Types of Join Points Primitive Lexical designators Type designators Control flow Types of Advice Before After Around Receptions Join

More information

Aspect-Oriented Programming

Aspect-Oriented Programming Aspect-Oriented Programming David Talby What is it? A new addition to the world of programming New concepts & language constructs New tools (aspect compiler, browser, debugger) Many examples & patterns

More information

Aspect-Oriented Programming. David Talby

Aspect-Oriented Programming. David Talby Aspect-Oriented Programming David Talby What is it? A new addition to the world of programming New concepts & language constructs New tools (aspect compiler, browser, debugger) Many examples & patterns

More information

Aspect-Oriented Programming

Aspect-Oriented Programming Aspect-Oriented Programming Anya Helene Bagge Department of Informatics University of Bergen LRDE Seminar, 26 Mar 2008 Anya Helene Bagge (UiB) Aspect-Oriented Programming LRDE Seminar, 26 Mar 2008 1 /

More information

AspectScope: An Outline Viewer for AspectJ Programs

AspectScope: An Outline Viewer for AspectJ Programs Vol. 6, No. 9, 2007 AspectScope: An Outline Viewer for AspectJ Programs Michihiro Horie, Tokyo Institute of Technology, Japan Shigeru Chiba, Tokyo Institute of Technology, Japan This paper presents the

More information

2003 by Manning Publications Co. All rights reserved.

2003 by Manning Publications Co. All rights reserved. For online information and ordering of this and other Manning books, go to www.manning.com. The publisher offers discounts on this book when ordered in quantity. For more information, please contact: Special

More information

Information systems modeling. Tomasz Kubik

Information systems modeling. Tomasz Kubik Information systems modeling Tomasz Kubik Aspect-oriented programming, AOP Systems are composed of several components, each responsible for a specific piece of functionality. But often these components

More information

Aspect Oriented Programming with AspectJ. Ted Leung Sauria Associates, LLC

Aspect Oriented Programming with AspectJ. Ted Leung Sauria Associates, LLC Aspect Oriented Programming with AspectJ Ted Leung Sauria Associates, LLC twl@sauria.com Overview Why do we need AOP? What is AOP AspectJ Why do we need AOP? Modular designs are not cut and dried Responsibilities

More information

Aspect Oriented Programming and the AspectJ

Aspect Oriented Programming and the AspectJ Aspect Oriented Programming and the AspectJ Tamás Kozsik (kto@elte.hu, http://kto.web.elte.hu/) Dept. Programming Languages and Compilers Eötvös Loránd University, Budapest (Hungary) Supported by GVOP

More information

Aspect-Oriented Programming

Aspect-Oriented Programming Aspect-Oriented Programming Johan Östlund johano@dsv.su.se Why AOP on this Course? AOP sets out to manage complexity ~ Modularizing software AOP is being accepted/adopted in ever increasing numbers both

More information

Course 6 7 November Adrian Iftene

Course 6 7 November Adrian Iftene Course 6 7 November 2016 Adrian Iftene adiftene@info.uaic.ro 1 Recapitulation course 5 BPMN AOP AOP Cross cutting concerns pointcuts advice AspectJ Examples In C#: NKalore 2 BPMN Elements Examples AOP

More information

aspect-oriented programming Modular Software Design with Crosscutting Interfaces

aspect-oriented programming Modular Software Design with Crosscutting Interfaces focus aspect-oriented programming Modular Software Design with Crosscutting Interfaces William G. Griswold and Macneil Shonle, University of California, San Diego Kevin Sullivan, Yuanyuan Song, Nishit

More information

aspect-oriented programming Modular Software Design with Crosscutting Interfaces

aspect-oriented programming Modular Software Design with Crosscutting Interfaces focus aspect-oriented programming Modular Software Design with Crosscutting Interfaces William G. Griswold and Macneil Shonle, University of California, San Diego Kevin Sullivan, Yuanyuan Song, Nishit

More information

Mapping Features to Aspects

Mapping Features to Aspects Mapping Features to Aspects The Road from Crosscutting to Product Lines (Work in Progress) Roberto E. Lopez-Herrejon Computing Laboratory Oxford University 1 Motivation Features Feature Informally: A characteristic

More information

Aspect-Oriented Programming

Aspect-Oriented Programming Aspect-Oriented Programming Based on the Example of AspectJ Prof. Harald Gall University of Zurich, Switzerland software evolution & architecture lab AOP is kind of a complicated one for me ( ) the idea

More information

Java Classes & Primitive Types

Java Classes & Primitive Types Java Classes & Primitive Types Rui Moreira Classes Ponto (from figgeom) x : int = 0 y : int = 0 n Attributes q Characteristics/properties of classes q Primitive types (e.g., char, byte, int, float, etc.)

More information

Java Classes & Primitive Types

Java Classes & Primitive Types Java Classes & Primitive Types Rui Moreira Classes Ponto (from figgeom) x : int = 0 y : int = 0 n Attributes q Characteristics/properties of classes q Primitive types (e.g., char, byte, int, float, etc.)

More information

Introduction to Programming Using Java (98-388)

Introduction to Programming Using Java (98-388) Introduction to Programming Using Java (98-388) Understand Java fundamentals Describe the use of main in a Java application Signature of main, why it is static; how to consume an instance of your own class;

More information

Experiences In Migrating An Industrial Application To Aspects by Abdelbaset Almasri & Iyad Albayouk

Experiences In Migrating An Industrial Application To Aspects by Abdelbaset Almasri & Iyad Albayouk This is an incomplete version of the thesis dissertation titled: Experiences In Migrating An Industrial Application To Aspects by Abdelbaset Almasri & Iyad Albayouk This version of the dissertation does

More information

Aspect-oriented programming with AspectJ. The building blocks of AspectJ: Join points, pointcuts and advices

Aspect-oriented programming with AspectJ. The building blocks of AspectJ: Join points, pointcuts and advices Aspect-oriented programming with AspectJ Dr. C. Constantinides Department of Computer Science and Software Engineering Concordia University Montreal, Quebec Canada August 11, 2016 1 / 124 The building

More information

Study Goals. Evaluation Criteria. Problems with OO Solution. Design Pattern Implementation in Java and AspectJ

Study Goals. Evaluation Criteria. Problems with OO Solution. Design Pattern Implementation in Java and AspectJ DCC / ICEx / UFMG Study Goals Design Pattern Implementation in Java and AspectJ Develop and compare Java and AspectJ implementations of the 23 GoF patterns Eduardo Figueiredo http://www.dcc.ufmg.br/~figueiredo

More information

Programming Languages

Programming Languages TECHNISCHE UNIVERSITÄT MÜNCHEN FAKULTÄT FÜR INFORMATIK Programming Languages Aspect Oriented Programming Dr. Michael Petter Winter 2017/18 Aspect Oriented Programming 1 / 34 Is modularity the key principle

More information

JAVA. Aspects (AOP) AspectJ

JAVA. Aspects (AOP) AspectJ JAVA Aspects (AOP) AspectJ AOP Aspect-oriented programming separation of concerns concern ~ a part of program code related to a particular functionality typically understood as an extension of OOP solves

More information

Modular software design with crosscutting interfaces

Modular software design with crosscutting interfaces Computer Science Publications Computer Science 1-2006 Modular software design with crosscutting interfaces W. G. Griswold University of California, San Diego M. Shonle University of California, San Diego

More information

Improving Incremental Development in AspectJ by Bounding Quantification

Improving Incremental Development in AspectJ by Bounding Quantification Improving Incremental Development in AspectJ by Bounding Quantification Roberto E. Lopez-Herrejon and Don Batory Department of Computer Sciences University of Texas at Austin Austin, Texas, 78712 U.S.A.

More information

SCALA AND ASPECTJ. Approaching Modularizing of Crosscutting. Ramnivas Laddad. Concerns. ramnivas

SCALA AND ASPECTJ. Approaching Modularizing of Crosscutting. Ramnivas Laddad. Concerns. ramnivas SCALA AND ASPECTJ Approaching Modularizing of Crosscutting Concerns Ramnivas Laddad ramnivas ramnivas!com @ramnivas Copyright Ramnivas Laddad. All rights reserved. @ramnivas Spring framework committer

More information

Chapter 4 Defining Classes I

Chapter 4 Defining Classes I Chapter 4 Defining Classes I This chapter introduces the idea that students can create their own classes and therefore their own objects. Introduced is the idea of methods and instance variables as the

More information

Separation of Concerns. AspectJ. What if the concerns are Cross-Cutting? SoC: Programming Paradigms. Key theme: Modularity and Encapsulation

Separation of Concerns. AspectJ. What if the concerns are Cross-Cutting? SoC: Programming Paradigms. Key theme: Modularity and Encapsulation Separation of Concerns and AspectJ EEC 625 Lecture #16 April 3, 2006 EEC 625: Software Design & Architecture Separation of Concerns Breaking a program into pieces that overlap in functionality as little

More information

Aspect-Oriented Programming and Aspect-J

Aspect-Oriented Programming and Aspect-J Aspect-Oriented Programming and Aspect-J TDDD05 Ola Leifer Most slides courtesy of Jens Gustafsson and Mikhail Chalabine Outline: Aspect-Oriented Programming New concepts introduced Crosscutting concern

More information

JML and Aspects: The Benefits of

JML and Aspects: The Benefits of JML and Aspects: The Benefits of Instrumenting JML Features with AspectJ Henrique Rebêlo Sérgio Soares Ricardo Lima Paulo Borba Márcio Cornélio Java Modeling Language Formal specification language for

More information

AspectC++ A Language Overview

AspectC++ A Language Overview AspectC++ A Language Overview c 2005 Olaf Spinczyk Friedrich-Alexander University Erlangen-Nuremberg Computer Science 4 May 20, 2005 This is an overview about the AspectC++ language, an

More information

CSC Java Programming, Fall Java Data Types and Control Constructs

CSC Java Programming, Fall Java Data Types and Control Constructs CSC 243 - Java Programming, Fall 2016 Java Data Types and Control Constructs Java Types In general, a type is collection of possible values Main categories of Java types: Primitive/built-in Object/Reference

More information

Package. A package is a set of related classes Syntax to put a class into a package: Two rules: Example:

Package. A package is a set of related classes Syntax to put a class into a package: Two rules: Example: Packages Package A package is a set of related classes Syntax to put a class into a package: package ; public class { } Two rules: q q A package declaration must always come

More information

Context-oriented Programming. Pascal Costanza (Vrije Universiteit Brussel, Belgium) Robert Hirschfeld (Hasso-Plattner-Institut, Potsdam, Germany)

Context-oriented Programming. Pascal Costanza (Vrije Universiteit Brussel, Belgium) Robert Hirschfeld (Hasso-Plattner-Institut, Potsdam, Germany) Context-oriented Programming Pascal Costanza (Vrije Universiteit Brussel, Belgium) Robert Hirschfeld (Hasso-Plattner-Institut, Potsdam, Germany) Programs are too static! Mobile devices Software agents

More information

A Unit Testing Framework for Aspects without Weaving

A Unit Testing Framework for Aspects without Weaving A Unit Testing Framework for Aspects without Weaving Yudai Yamazaki l01104@sic.shibaura-it.ac.jp Kouhei Sakurai sakurai@komiya.ise.shibaura-it.ac.jp Saeko Matsuura matsuura@se.shibaura-it.ac.jp Hidehiko

More information

An introduction to Java II

An introduction to Java II An introduction to Java II Bruce Eckel, Thinking in Java, 4th edition, PrenticeHall, New Jersey, cf. http://mindview.net/books/tij4 jvo@ualg.pt José Valente de Oliveira 4-1 Java: Generalities A little

More information

CS313D: ADVANCED PROGRAMMING LANGUAGE

CS313D: ADVANCED PROGRAMMING LANGUAGE CS313D: ADVANCED PROGRAMMING LANGUAGE Computer Science Department Lecture 3: C# language basics Lecture Contents 2 C# basics Conditions Loops Methods Arrays Dr. Amal Khalifa, Spr 2015 3 Conditions and

More information

AJDT: Getting started with Aspect-Oriented Programming in Eclipse

AJDT: Getting started with Aspect-Oriented Programming in Eclipse AJDT: Getting started with Aspect-Oriented Programming in Eclipse Matt Chapman IBM Java Technology Hursley, UK AJDT Committer Andy Clement IBM Java Technology Hursley, UK AJDT & AspectJ Committer Mik Kersten

More information

Around Weaving in abc

Around Weaving in abc Around Weaving in abc Objectives Avoid heap allocations Inlining not as the general strategy to avoid code duplication Keep code in original classes to avoid visibility problems The starting point Around

More information

Aspect-Oriented Programming and Modular Reasoning

Aspect-Oriented Programming and Modular Reasoning Copyright 2004 Gregor Kiczales, Mira Mezini. All rights reserved. 1 Aspect-Oriented Programming and Modular Reasoning Gregor Kiczales University of British Columbia gregork@acm.org Mira Mezini Technische

More information

04/06/2013. Study Goals. Design Patterns in AspectJ. Evaluation Criteria. Problems with OO Solution

04/06/2013. Study Goals. Design Patterns in AspectJ. Evaluation Criteria. Problems with OO Solution DCC / ICEx / UFMG Study Goals Design Patterns in AspectJ Develop and compare Java and AspectJ implementations of the 23 GoF patterns Eduardo Figueiredo http://www.dcc.ufmg.br/~figueiredo Aim to keep the

More information

Aspect-Oriented Programming and Modular Reasoning

Aspect-Oriented Programming and Modular Reasoning Aspect-Oriented Programming and Modular Reasoning Gregor Kiczales University of British Columbia 2366 Main Mall Vancouver, BC, Canada gregork@acm.org Mira Mezini Technische Universität Darmstadt Hochschulstrasse

More information

AspectMatlab Reference Manual

AspectMatlab Reference Manual AspectMatlab Reference Manual Andrew Bodzay May 18, 2015 1 Introduction AspectMatlab is an extension of Matlab, which supports the notions of patterns and actions. An aspect in AspectMatlab looks very

More information

Homework 5: Aspect-Oriented Programming and AspectJ

Homework 5: Aspect-Oriented Programming and AspectJ Com S 541 Programming Languages 1 November 30, 2005 Homework 5: Aspect-Oriented Programming and AspectJ Due: Tuesday, December 6, 2005. This homework should all be done individually. Its purpose is to

More information

3.1 Class Declaration

3.1 Class Declaration Chapter 3 Classes and Objects OBJECTIVES To be able to declare classes To understand object references To understand the mechanism of parameter passing To be able to use static member and instance member

More information

EECS168 Exam 3 Review

EECS168 Exam 3 Review EECS168 Exam 3 Review Exam 3 Time: 2pm-2:50pm Monday Nov 5 Closed book, closed notes. Calculators or other electronic devices are not permitted or required. If you are unable to attend an exam for any

More information

Aspects & Modular Reasoning. Robby Findler University of Chicago

Aspects & Modular Reasoning. Robby Findler University of Chicago Aspects & Modular Reasoning Robby Findler University of Chicago 1 When can you replace one expression with another? 1+1 2 2 When can you replace one expression with another? For any context, C C[1+1] C[2]

More information

Enterprise Informatization LECTURE

Enterprise Informatization LECTURE Enterprise Informatization LECTURE Piotr Zabawa, PhD. Eng. IBM/Rational Certified Consultant e-mail: pzabawa@pk.edu.pl www: http://www.pk.edu.pl/~pzabawa/en 07.10.2011 Lecture 7 Aspect-Oriented Programming

More information

Method Slots: Supporting Methods, Events, and Advices by a Single Language Construct

Method Slots: Supporting Methods, Events, and Advices by a Single Language Construct Method Slots: Supporting Methods, Events, and Advices by a Single Language Construct YungYu Zhuang and Shigeru Chiba The University of Tokyo More and more paradigms are supported by dedicated constructs

More information

Specifying Pointcuts in AspectJ

Specifying Pointcuts in AspectJ Specifying Pointcuts in AspectJ Yi Wang Department of Computer Science Shanghai Jiao Tong University 800 Dongchuan Rd, Shanghai, 200240, China yi_wang@sjtu.edu.cn Jianjun Zhao Department of Computer Science

More information

Aspect-Oriented Programming with C++ and AspectC++

Aspect-Oriented Programming with C++ and AspectC++ Aspect-Oriented Programming with C++ and AspectC++ AOSD 2007 Tutorial University of Erlangen-Nuremberg Computer Science 4 Presenters Daniel Lohmann dl@aspectc.org University of Erlangen-Nuremberg, Germany

More information

Array. Prepared By - Rifat Shahriyar

Array. Prepared By - Rifat Shahriyar Java More Details Array 2 Arrays A group of variables containing values that all have the same type Arrays are fixed length entities In Java, arrays are objects, so they are considered reference types

More information

Background. Reflection. The Class Class. How Objects Work

Background. Reflection. The Class Class. How Objects Work Background Reflection Turing's great insight: programs are just another kind of data Source code is text Manipulate it line by line, or by parsing expressions Compiled programs are data, too Integers and

More information

Program Instrumentation for Debugging and Monitoring with AspectC++

Program Instrumentation for Debugging and Monitoring with AspectC++ Program Instrumentation for Debugging and Monitoring with AspectC++ Daniel Mahrenholz, Olaf Spinczyk, and Wolfgang Schröder-Preikschat University of Magdeburg Universitätsplatz 2 D-39106 Magdeburg, Germany

More information

CMPT 115. C tutorial for students who took 111 in Java. University of Saskatchewan. Mark G. Eramian, Ian McQuillan CMPT 115 1/32

CMPT 115. C tutorial for students who took 111 in Java. University of Saskatchewan. Mark G. Eramian, Ian McQuillan CMPT 115 1/32 CMPT 115 C tutorial for students who took 111 in Java Mark G. Eramian Ian McQuillan University of Saskatchewan Mark G. Eramian, Ian McQuillan CMPT 115 1/32 Part I Starting out Mark G. Eramian, Ian McQuillan

More information

An Introduction to Aspect-Oriented Programming

An Introduction to Aspect-Oriented Programming An Introduction to Aspect-Oriented Programming By Ken Wing Kuen Lee Reading Assignment COMP 610E 2002 Spring Software Development of E-Business Applications The Hong Kong University of Science

More information

GenUTest: An Automatic Unit Test & Mock Aspect Generation Tool

GenUTest: An Automatic Unit Test & Mock Aspect Generation Tool Tel Aviv University The Raymond and Beverly Sackler Faculty of Exact Sciences GenUTest: An Automatic Unit Test & Mock Aspect Generation Tool Thesis submitted in partial fulfillment of the requirements

More information

Java How to Program, 10/e. Copyright by Pearson Education, Inc. All Rights Reserved.

Java How to Program, 10/e. Copyright by Pearson Education, Inc. All Rights Reserved. Java How to Program, 10/e Education, Inc. All Rights Reserved. Each class you create becomes a new type that can be used to declare variables and create objects. You can declare new classes as needed;

More information

DD2460 Software Safety and Security: Part III Exercises session 2: Type + Jif

DD2460 Software Safety and Security: Part III Exercises session 2: Type + Jif DD2460 Software Safety and Security: Part III Exercises session 2: Type + Jif Gurvan Le Guernic adapted from Aslan Askarov DD2460 (III, E2) February 22 st, 2012 1 Noninterference type systems challenge

More information

Slicing Aspect-Oriented Software

Slicing Aspect-Oriented Software Slicing Aspect-Oriented Software Jianjun Zhao Department of Computer Science and Engineering Fukuoka Institute of Technology 3-30-1 Wajiro-Higashi, Higashi-ku, Fukuoka 811-0295, Japan zhao@cs.fit.ac.jp

More information

Composition Graphs: a Foundation for Reasoning about Aspect-Oriented Composition

Composition Graphs: a Foundation for Reasoning about Aspect-Oriented Composition s: a Foundation for Reasoning about Aspect-Oriented - Position Paper - István Nagy Mehmet Aksit Lodewijk Bergmans TRESE Software Engineering group, Faculty of Computer Science, University of Twente P.O.

More information

Some language elements described in this text are not yet supported in the current JAsCo version (0.8.x). These are: Multiple hook constructors

Some language elements described in this text are not yet supported in the current JAsCo version (0.8.x). These are: Multiple hook constructors !IMPORTANT! Some language elements described in this text are not yet supported in the current JAsCo version (0.8.x). These are: Multiple hook constructors Gotchas when migrating to 0.8.5 from an earlier

More information

Building Java Programs

Building Java Programs Building Java Programs Chapter 8 Lecture 8-3: Encapsulation; Homework 8 (Critters) reading: 8.3-8.4 Encapsulation reading: 8.4 2 Encapsulation encapsulation: Hiding implementation details from clients.

More information

Assignment 2 - Specifications and Modeling

Assignment 2 - Specifications and Modeling Assignment 2 - Specifications and Modeling Exercise 1 A way to document the code is to use contracts. For this exercise, you will have to consider: preconditions: the conditions the caller of a method

More information

Creating an object Instance variables

Creating an object Instance variables Introduction to Objects: Semantics and Syntax Defining i an object Creating an object Instance variables Instance methods What is OOP? Object-oriented programming (constructing software using objects)

More information

Object Oriented Design

Object Oriented Design Object Oriented Design Chapter 9 Initializing a non-static data member in the class definition is a syntax error 1 9.2 Time Class Case Study In Fig. 9.1, the class definition is enclosed in the following

More information

AP COMPUTER SCIENCE JAVA CONCEPTS IV: RESERVED WORDS

AP COMPUTER SCIENCE JAVA CONCEPTS IV: RESERVED WORDS AP COMPUTER SCIENCE JAVA CONCEPTS IV: RESERVED WORDS PAUL L. BAILEY Abstract. This documents amalgamates various descriptions found on the internet, mostly from Oracle or Wikipedia. Very little of this

More information

Building Java Programs

Building Java Programs Building Java Programs Chapter 8 Lecture 18: Classes and Objects reading: 8.1-8.2 (Slides adapted from Stuart Reges, Hélène Martin, and Marty Stepp) 2 File output reading: 6.4-6.5 3 Output to files PrintStream:

More information

CMSC 433 Section 0101 Fall 2012 Midterm Exam #1

CMSC 433 Section 0101 Fall 2012 Midterm Exam #1 Name: CMSC 433 Section 0101 Fall 2012 Midterm Exam #1 Directions: Test is closed book, closed notes. Answer every question; write solutions in spaces provided. Use backs of pages for scratch work. Good

More information

Chapter 6 Introduction to Defining Classes

Chapter 6 Introduction to Defining Classes Introduction to Defining Classes Fundamentals of Java: AP Computer Science Essentials, 4th Edition 1 Objectives Design and implement a simple class from user requirements. Organize a program in terms of

More information

Refactoring Aspect-Oriented Software

Refactoring Aspect-Oriented Software Refactoring Aspect-Oriented Software by Shimon Rura A Thesis Submitted in partial fulfillment of of the requirements for the Degree of Bachelor of Arts with Honors in Computer Science WILLIAMS COLLEGE

More information

Language-Independent Aspect-Oriented Programming

Language-Independent Aspect-Oriented Programming Language-Independent Aspect-Oriented Programming Donal Lafferty Donal.Lafferty@cs.tcd.ie Distributed Systems Group Department of Computer Science Trinity College Dublin Vinny Cahill Vinny.Cahill@cs.tcd.ie

More information

CS11 Intro C++ Spring 2018 Lecture 3

CS11 Intro C++ Spring 2018 Lecture 3 CS11 Intro C++ Spring 2018 Lecture 3 C++ File I/O We have already seen C++ stream I/O #include cout > name; cout

More information

Chapter 5: Procedural abstraction. Function procedures. Function procedures. Proper procedures and function procedures

Chapter 5: Procedural abstraction. Function procedures. Function procedures. Proper procedures and function procedures Chapter 5: Procedural abstraction Proper procedures and function procedures Abstraction in programming enables distinction: What a program unit does How a program unit works This enables separation of

More information

Container Vs. Definition Classes. Container Class

Container Vs. Definition Classes. Container Class Overview Abstraction Defining new classes Instance variables Constructors Defining methods and passing parameters Method/constructor overloading Encapsulation Visibility modifiers Static members 14 November

More information

Object Oriented Programming

Object Oriented Programming Object Oriented Programming Java lecture (10.2) Exception Handling 1 Outline Throw Throws Finally 2 Throw we have only been catching exceptions that are thrown by the Java run-time system. However, it

More information

APTE: Automated Pointcut Testing for AspectJ Programs

APTE: Automated Pointcut Testing for AspectJ Programs APTE: Automated Pointcut Testing for AspectJ Programs Prasanth Anbalagan Department of Computer Science North Carolina State University Raleigh, NC 27695 panbala@ncsu.edu Tao Xie Department of Computer

More information

Towards Regression Test Selection for AspectJ Programs

Towards Regression Test Selection for AspectJ Programs Towards Regression Test Selection for AspectJ Programs Jianjun Zhao Department of Computer Science and Engineering Shanghai Jiao Tong University 800 Dongchuan Road, Shanghai 200240, China zhao-jj@cs.sjtu.edu.cn

More information

CS111: PROGRAMMING LANGUAGE II

CS111: PROGRAMMING LANGUAGE II CS111: PROGRAMMING LANGUAGE II Computer Science Department Lecture 1(c): Java Basics (II) Lecture Contents Java basics (part II) Conditions Loops Methods Conditions & Branching Conditional Statements A

More information

Testing Aspect-Oriented Software

Testing Aspect-Oriented Software Project Report Testing Aspect-Oriented Software Fayezin Islam MSc in Advanced Software Engineering 2006/2007 School of Physical Sciences and Engineering King s College London Supervised by Professor Mark

More information

Detecting Redundant Unit Tests for AspectJ Programs

Detecting Redundant Unit Tests for AspectJ Programs Detecting Redundant Unit Tests for AspectJ Programs Tao Xie 1 Jianjun Zhao 2 Darko Marinov 3 David Notkin 4 1 North Carolina State University 2 Shanghai Jiaotong University 3 University of Illinois at

More information