Aspect Oriented Programming Written by Michael Beder.

Slides:



Advertisements
Similar presentations
AspectWerkz 2 - and the road to AspectJ 5 Jonas Bonér Senior Software Engineer BEA Systems.
Advertisements

A Brief Introduction to Aspect-Oriented Programming Zhenxiao Yang.
Chapter 14 Graph class design John Keyser’s Modifications of Slides by Bjarne Stroustrup
Aspect Oriented Programming. AOP Contents 1 Overview 2 Terminology 3 The Problem 4 The Solution 4 Join point models 5 Implementation 6 Terminology Review.
ASTA Aspect Software Testing Assistant Juha Gustafsson, Juha Taina, Jukka Viljamaa University of Helsinki.
1 JAC : Aspect Oriented Programming in Java An article review by Yuval Nir and Limor Lahiani.
© 2007 ATLAS Nantes 1 Atlas Model Weaver Use Case: Aspect Oriented Modeling Marcos Didonet Del Fabro Atlas Group (INRIA & LINA), Université de Nantes,
©Ian Sommerville 2006Software Engineering, 8th edition. Chapter 32 Slide 1 Aspect-oriented Software Development.
Figures – Chapter 21. Figure 21.1 Cross-cutting concerns.
Overview of AspectJ Aspect Oriented Software Development Seminar Technion presented by Oren Mishali.
Aspect-Oriented Programming In Eclipse ® Aspect-Oriented Programming in Eclipse with AspectJ Dr Helen Hawkins and Sian January.
University of British Columbia Software Practices Lab Fluid AOP Join Point Models Terry Hon Gregor Kiczales.
University of British Columbia Software Practices Lab 2005 CASCON A Fluid AOP Editor Terry Hon Gregor Kiczales.
October - December 2013CSC5021: The Problem With Aspects (J P Gibson)1 The Problem With Aspects (AOP) A style of programming that attempts to abstract.
Optimizing AspectJ Pavel Avgustinov, Aske Simon Christensen, Laurie Hendren, Sascha Kuzins, Jennifer Lhotak, Ondrej Lhotak, Oege de Moor, Damien Sereni,
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.
Categories of Aspects Shmuel Katz Computer Science Department The Technion Haifa, Israel.
1 Evan Korth New York University Inheritance and Polymorphism Professor Evan Korth New York University.
1 Evan Korth New York University Inheritance and Polymorphism Professor Evan Korth New York University.
Review David Rabinowitz. March 3rd, 2004 Object Oriented Design Course 2 Review What have we done during the course? Which topics we have not discussed?
More on AspectJ. aspect MoveTracking { private static boolean _flag = false; public static boolean testAndClear() { boolean result = _flag; _flag = false;
Introduction to Aspect- Oriented Programming CS 3360 Gregor Kiczales, et. al. Getting started with AspectJ, CACM, 44(10):59-65, October Fall 2012.
Outline Introduction Problem Statement Object-Oriented Design Aspect-Oriented Design Conclusion Demo.
Taming Obliviousness in Aspects with Data-flow Analysis and Design by Contract Tim Molderez and Dirk Janssens Ansymo Antwerp Systems and Software Modelling.
Software Engineering Laboratory, Department of Computer Science, Graduate School of Information Science and Technology, Osaka University 1 Debugging Support.
Introduction to AOP.
Introduction to Aspect Oriented Programming Presented By: Kotaiah Choudary. Ravipati M.Tech IInd Year. School of Info. Tech.
Aspect Oriented Programming (AOP) in.NET Brent Krueger 12/20/13.
Aspect Oriented Programming Razieh Asadi University of Science & Technology Mazandran Babol Aspect Component Based Software Engineering (ACBSE)
VERIFICATION OF ASPECT ORIENTED MODELS BY DON MARTIN JAYASHREE VENKIPURAM PATHANGI PIYUSH SRIVASTAVA REFERENCES F. Mostefaoui and J. Vachon,” Design level.
Aspect Oriented Programming Scott Nykl CSSE 411 Senior Seminar.
©Ian Sommerville 2006Software Engineering, 8th edition. Chapter 32 Slide 1 Aspect-oriented Software Development 1.
Aspect Oriented Programming Sumathie Sundaresan CS590 :: Summer 2007 June 30, 2007.
POSL (Principles of Software Languages) Gr. Kyushu Institute of Technology, Japan Pointcut-based Architectural Interface.
Aspect Oriented Programming Gülşah KARADUMAN.
VERIFICATION OF ASPECT-ORIENTED MODELS Review of Aspect-Oriented Definitions aspect – crosscutting concern that may involve multiple classes pointcut –
AOSD1 Aspect-Oriented Software Design Karl Lieberherr Theo Skotiniotis.
AOP-1 Aspect Oriented Programming. AOP-2 Aspects of AOP and Related Tools Limitation of OO Separation of Concerns Aspect Oriented programming AspectJ.
Introduction Better Faster Cheaper (pick any two) On-going issue that continues to motivate research in software engineering Applications: –continue to.
Virtual Support for Dynamic Join Points C. Bockisch, M. Haupt, M. Mezini, K. Ostermann Presented by Itai Sharon
Recursion. Math Review Given the following sequence: a 1 = 1 a n = 2*a n-1 OR a n+1 = 2*a n What are the values of the following? a 2 = a 3 = a 4 =
Aspect-Oriented Programming and Modular Reasoning G. KiczalesM. Mezini Presented by Alex Berendeyev.
IDENTIFYING SEMANTIC DIFFERENCES IN ASPECTJ PROGRAMS Martin Görg and Jianjun Zhao Computer Science Department, Shanghai Jiao Tong University.
Region Pointcut for AspectJ Shumpei Akai Shigeru Chiba Muga Nishizawa.
AspectJ – AOP for Java Tom Janofsky. Instructor at Penn State Abington Consultant with Chariot Solutions JUG Member.
Software Engineering Laboratory, Department of Computer Science, Graduate School of Information Science and Technology, Osaka University IWPSE 2003 Program.
Chapter 8: Aspect Oriented Programming Omar Meqdadi SE 3860 Lecture 8 Department of Computer Science and Software Engineering University of Wisconsin-Platteville.
Aspect Oriented Development Alex Beatty.  Purpose  Cross-cutting Concerns  Join Points, Pointcuts, and Advices  Weaving  Invasive vs. Non-Invasive.
AOP-Driven Variability in Software Product Lines Vander Alves, Ayla Dantas, and Paulo Borba Informatics Center – UFPE – Brazil
Java Polymorphism. What we have learned Polymorphism is one of the three very powerful and useful mechanisms offered by OOP. What are the other two?
问题 Code scattering Blocks of duplicated code Blocks of complementary code, and different modules implementing complementary parts of the concern Code.
aspectj tools new and noteworthy Mik Kersten University of British Columbia Adrian Colyer IBM Hursley OOPSLA, October
Introduction to Yan Cui Aspect Oriented Programming by
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.
Aspect-Oriented Software Development (AOSD)
1 An AOP Implementation Framework for Extending Join Point Models Naoyasu Ubayashi(Kyushu Institute of Technology, Japan) Hidehiko Masuhara(University.
Implementing Distribution and Persistence Aspects with AspectJ WAS CLASS.
L’origine dei mali: le dipendenze tra componenti Stefano Leli 14° Workshop DotNetMarche Venerdì 16 aprile
PPL 2004, Gamagori, AICHI1 Remote Pointcut - A Language Construct for Distributed AOP Muga Nishizawa (Tokyo Tech, Japan) Shigeru Chiba (Tokyo Tech, Japan)
Software Engineering Lecture 7
Aspect-Oriented Programming with the Eclipse AspectJ plug-in
A Brief Introduction to Aspect-Oriented Programming
Structuring Adaptive Applications using AspectJ and AOM
AspectAda Aspect-Oriented Programming for Ada95
Aspect Oriented Software Design
Refactoring the Aspectizable Interfaces: An Empirical Assessment
Presentation transcript:

Aspect Oriented Programming Written by Michael Beder

Aspect Oriented Programming2 Agenda Why Aspects? Examples –Class Invariants –Debugging Basic Terminology AspectJ Question

Aspect Oriented Programming3 Why Aspects? Some design and implementation problems are not related to a specific class or module. –Asserting (Invariants, Parameters, Pre/Post conditions). –Debugging. –Logging. –Security. –Robustness. Such problems relate to crosscutting concerns of the software. –May originate in Non-Functional requirements. Solving them using regular OOP methods leads to scattering and tangling. An Aspect solution offers a uniform treatment of the problem.

Aspect Oriented Programming4 Crosscutting concerns Packages Security Logging Asserting Robustness

Aspect Oriented Programming5 Case Study: Class Invariants Class Rectangle { private Point center; private int width, height; public move(Point to) {…} public setDimensions(int width, int height) {…} public draw() {…} } Class Invariant: (width > 0) && (height > 0) && (center.x > 0) && (center.y > 0). We want to assert the fulfillment of the invariant. How to do it?

Aspect Oriented Programming6 Solution I Class Rectangle { private Point center; private int width, height; public move(Point to) {if (width > 0) && …} public setDimensions(int width, int height) {if (width > 0) … } public draw() {if (width > 0) … } } Code multiplication. What if the invariance changes? Hard to maintain. Only disadvantages.

Aspect Oriented Programming7 Solution II Class Rectangle { private Point center; private int width, height; private checkInvariant() {if (width > 0) && …} public move(Point to) {checkInvariant() …} public setDimensions(int width, int height) {checkInvariant() …} public draw() {checkInvariant() …} } Code multiplication! Adding additional methods? Still not elegant and still scattered. What limits us? Can we do better?

Aspect Oriented Programming8 A Moment of Truth Invariant fulfillment is not a part of the functionality of Rectangle. It is a higher property derived from the functionality. Asserting is performed in places that have a common pattern. –At the beginning of each method. The execution mechanism forces us to scatter the responsible code among the methods. Why not use another execution mechanism? Applying the scattering pattern in a uniform way

Aspect Oriented Programming9 Basic Terminology A Join Point is a well-defined event in the execution of the program. –e.g. a specific method call, a specific block execution, handling a specific exception, etc. –May be or may be not realized in a specific program execution. –Has a dynamic context and identity. a.f() … while (…) { … } … a.f() Program execution join point 1 join point 2 join point 3 Is join point 1 is the same as joint point 3 ?

Aspect Oriented Programming10 Basic Terminology – cont. A Pointcut is a syntactic construct that defines a set of join points. –e.g. a method call in the code, the method itself (all calls), change of some variable. a.f() … while (…) { … } … a.f() Program execution join point 1 join point 2 join point 3 pointcut 1: “call to method f” a syntactic construct

Aspect Oriented Programming11 Basic Terminology – cont. An Advice is a connection between a pointcut and an action. before advice: action to be done right before the program proceeds to a join point defined by the pointcut. after advice: action to be done right after the program leaves a join point defined by the pointcut. Define the scattering pattern as a pointcut Implement the solution as an advice on the pointcut

Aspect Oriented Programming12 AspectJ General-purpose, aspect-oriented extension to Java. –Every valid Java program is a valid AspectJ program. May 25, 2004 – AspectJ 1.2 released. AspectJ enables definition of join points, pointcuts advices and more. General workflow: –Implementing the core concerns using Java. –Implementing the crosscutting concerns using AspectJ extension. –Weaving both implementations using ajc (no need for javac). Compiler Java Code AspectJ Code Java object code AspectJ Weaver

Aspect Oriented Programming13 Solution III: Using AspectJ Class Rectangle { private Point center; private int width, height; public move(Point to) {…} public setDimensions(int width, int height) {…} public draw() {…} } pointcut checkInvariance(Rectangle rect) : call(* Rectangle.*(..)) && target(rect); before(Rectangle rect) : checkInvariance(rect) { if (rect.width > 0) && (rect.height > 0) && … } Rectangle’s code is not changed Corresponds to the scattering pattern problem specific implementation ‘before’ advice

Aspect Oriented Programming14 Case Study: Debugging Class Rectangle { private Point center; private int width, height; public move(Point to) {…} public setDimensions(int width, int height) {…} public draw() {…} } Suppose we want to trace each change of height in move(). How to do it? Print height before each use? Use setHeight(), getHeight() only? –works, but too radical. An Aspect solution!

Aspect Oriented Programming15 Debugging – cont. Class Rectangle { private Point center; private int width, height; public void move(Point to) {…} public void setDimensions(int width, int height) {…} public void draw() {…} } pointcut heightInMove(Rectangle rect, int newHeight) : execution(public void Rectangle.move(Point)) && target(rect) && set(private Rectangle.height) && args(newHeight); after(Rectangle rect, int newHeight) : heightInMove(rect, newHeight) { System.out.println(“Height of Rectangle ” + rect.toString() + “ is changed to “ + newHeight); } ‘after’ advice

Aspect Oriented Programming16 Solution Advantages No scattering. –The responsible code is concentrated in one place. No tangling. –Suppose we want to build a stack of all height’s values. Its definition and update will be concentrated in one place. The debugged class remains unchanged. –Reduces the chance of creating new bugs while debugging. Changes are made easily. –Tracing height before its change. –Tracing every change of height.

Aspect Oriented Programming17 Question (from exam) After implementing the product, the developers of ABC inc. company realized that they forgot to implement logging of every action. One of the developers suggested to make the change in the following way: For each class Foo create a derived class FooWithLog that adds logging: Foo int action () { // do stuff } FooWithLog int action () { log(“starting action”); int value = super.action(); log(“ending action”); return value; }

Aspect Oriented Programming18 Question (from exam) – cont. 1. What are the main advantages and disadvantages of this solution? 2. Describe a better solution using the Abstract Factory Pattern. Draw the class diagram. 3. Describe another solution using different language/mechanism. Compare this solution to the previous solution.