Introduction to Aspect- Oriented Programming CS 3360 Gregor Kiczales, et. al. Getting started with AspectJ, CACM, 44(10):59-65, October 2001. Fall 2012.

Slides:



Advertisements
Similar presentations
Aspect Oriented Programming. AOP Contents 1 Overview 2 Terminology 3 The Problem 4 The Solution 4 Join point models 5 Implementation 6 Terminology Review.
Advertisements

ASTA Aspect Software Testing Assistant Juha Gustafsson, Juha Taina, Jukka Viljamaa University of Helsinki.
©Ian Sommerville 2006Software Engineering, 8th edition. Chapter 32 Slide 1 Aspect-oriented Software Development.
Secure Systems Research Group - FAU Aspect Oriented Programming Carlos Oviedo Secure Systems Research Group.
Introduction to Object-Oriented Programming CS 21a: Introduction to Computing I First Semester,
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.
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 Written by Michael Beder.
More on AspectJ. aspect MoveTracking { private static boolean _flag = false; public static boolean testAndClear() { boolean result = _flag; _flag = false;
Java Methods By J. W. Rider. Java Methods Modularity Declaring methods –Header, signature, prototype Static Void Local variables –this Return Reentrancy.
CSM-Java Programming-I Spring,2005 Introduction to Objects and Classes Lesson - 1.
Outline Introduction Problem Statement Object-Oriented Design Aspect-Oriented Design Conclusion Demo.
Developing Adaptive J2ME Applications Using AspectJ Ayla Débora and Paulo Borba {add, Centro de Informática - UFPE.
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.
Introduction to Object-Oriented Programming
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.
Introduction to Java and Object-Oriented Programming AJSS Computer Camp Department of Information Systems and Computer Science Ateneo de Manila University.
©Ian Sommerville 2006Software Engineering, 8th edition. Chapter 32 Slide 1 Aspect-oriented Software Development 1.
CS 11 java track: lecture 1 Administrivia need a CS cluster account cgi-bin/sysadmin/account_request.cgi need to know UNIX
Aspect Oriented Programming Sumathie Sundaresan CS590 :: Summer 2007 June 30, 2007.
Take-Home Final COM 3205 Fall Stamp Coupling Def: data structure is passed as parameter, but called method operates on only some of the` individual.
Aspect Oriented Programming Gülşah KARADUMAN.
A Distributed Aspect-Oriented System for J2EE Applications Muga Nishizawa and Shigeru Chiba (Tokyo Institute of Technology, Japan) Background - As benefits.
AOSD1 Aspect-Oriented Software Design Karl Lieberherr Theo Skotiniotis.
TRANSPARENT EXTENSION OF SINGLE- USER APPLICATIONS TO MULTI-USER REAL-TIME COLLABORATIVE SYSTEMS An Aspect Oriented Approach to Framework Integration ICEIS.
AOP-1 Aspect Oriented Programming. AOP-2 Aspects of AOP and Related Tools Limitation of OO Separation of Concerns Aspect Oriented programming AspectJ.
1 Proving aspect-oriented programming laws Leonardo Cole Paulo Borba Alexandre Mota Informatics Center Federal University of.
1 5/30/98LCR ‘98 BBN Technologies QoS Aspect Languages and their Runtime Integration Joseph P. Loyall, David E. Bakken, Richard E. Schantz, John A. Zinky,
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.
IDENTIFYING SEMANTIC DIFFERENCES IN ASPECTJ PROGRAMS Martin Görg and Jianjun Zhao Computer Science Department, Shanghai Jiao Tong University.
Inter-Type Declarations in AspectJ Awais Rashid Steffen Zschaler © Awais Rashid, Steffen Zschaler 2009.
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.
Demeter Aspects We study techniques for the emerging area of Aspect-Oriented Software Development and focus on the following areas:  Aspectual Collaborations.
Pengantar OOP Class-Java. 2 Software Development Tools Using Sun Java SDK alone Source File(s) (.java) Programmer Compiler (javac) Class File(s) (.class)
Trip Report: DSL ‘97 October 15-17, 1997 Santa Barbara CA.
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.
1 Deriving Refactorings for AspectJ Leonardo Cole Paulo Borba Informatics Center Federal University of Pernambuco Brazil.
Programmeren 1 6 september 2010 HOORCOLLEGE 2: INTERACTIE EN CONDITIES PROGRAMMEREN 1 6 SEPTEMBER 2009 Software Systems - Programming - Week.
问题 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.
AspectScope: An Outline Viewer for AspectJ Programs Michihiro Horie, Shigeru Chiba Tokyo Institute of Technology, Japan.
Copyright 1997, 1998 Xerox Corporation - Dijkstra, A discipline of programming, 1976 last chapter, In retrospect “To my taste the main characteristic of.
AOP with AspectJ Awais Rashid, Steffen Zschaler © Awais Rashid, Steffen Zschaler 2009.
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.
1 Aspectual Caml an Aspect-Oriented Functional Language Hideaki Tatsuzawa Hidehiko Masuhara Akinori Yonezawa University of Tokyo.
PPL 2004, Gamagori, AICHI1 Remote Pointcut - A Language Construct for Distributed AOP Muga Nishizawa (Tokyo Tech, Japan) Shigeru Chiba (Tokyo Tech, Japan)
Aspect-Oriented Programming with the Eclipse AspectJ plug-in
CompSci 230 Software Construction
Demeter Aspects Who We Are Aspectual Collaborations
Lecture 21: Crosscutting Aspect-Oriented Programming
Aspect-Oriented Programming
Structuring Adaptive Applications using AspectJ and AOM
Aspect-oriented programming
Aspect Oriented Programming
Presentation transcript:

Introduction to Aspect- Oriented Programming CS 3360 Gregor Kiczales, et. al. Getting started with AspectJ, CACM, 44(10):59-65, October Fall 2012

2 Logging… Where is logging in some large server code?  red shows lines of code that handle logging  not in just one place  not even in a small number of places Not Modularized!

3 Session Expiration…

4 Questions Other things like this? Why is it bad to handle this all over the code?

5 The Problem Code scattering  Single issue implemented in multiple modules Logging Accounting Internet banking Customer Teller

6 Can We Do Better? Clear Crosscutting Structure All modules use the trace facility in a consistent way, i.e., entering methods and exiting methods. TraceSupport

7 ASPECT-ORIENTED PROGRAMMING

8 Tracing as Aspect TraceSupport // pseudo code aspect MyTracing before method execution do: indicate beginning of execution after method execution do: indicate end of execution

9 The Idea of AOP Crosscutting is inherent in complex systems Crosscutting concerns have:  Clear purpose  Natural structure, e.g.,defined set of methods, module boundary crossings, points of resource utilization, and lines of dataflow. So, why not capture the structure of crosscutting concerns explicitly?  in a modular way  with linguistic and tool support Aspects are well-modularized crosscutting concerns

10 Language Support …

11 Language Support … (cont’d)

ASPECT-J: A BRIEF INTRO 12

13 An Overview of AspectJ Supports Aspect OP A small extension to Java A general-purpose AOP language  Just as Java is a general-purpose OO language Active research community: conferences, journals, books, software, etc. URL:

14 Components of Aspect-j Join points Pointcuts Advices Aspects

15 First AspectJ Program Crosscutting HelloWorld program public class HelloWorld { public void say(String msg) { System.out.println(msg); } public static void main(String [] args) { new HelloWorld().say(“Hello, world!”); }

16 Crosscutting HelloWorld public aspect MilitaryProtocol { pointcut sayPoint() : execution (void HelloWorld.say(String)); after() : sayPoint() { System.out.println("Over!"); }

17 Compiling and Running % javac HelloWorld.java % java HelloWorld Hello, world! % ajc HelloWorld.java MilitaryProtocol.aj % java HelloWorld Hello, world! Over!

18 Anatomy of MiltaryProtocol public aspect MilitaryProtocol { pointcut sayPoint() : execution (void HelloWorld.say(String)); after() : sayPoint() { System.out.println("Over!"); } advice definition pointcut declaration aspect definition

19 Definitions Join points  Well-defined points in execution of program Pointcuts  A means to referring to collections of join points and certain values at those join points  E.g., pointcut sayPoint() : execution (void HelloWorld.say(String)); Advices  Method-like constructs used to define additional behavior at join points  E.g., after() : sayPoint() { System.out.println("Over!"); Aspects  Units of modular crosscutting implementation, composed of pointcuts, advice, and ordinary Java member declarations.

20 Join Points Several kinds of join points  Method and constructor call  Method and constructor body execution  Reading (getting) a field  Writing (setting) to a field  Initialization of an object  Static initialization of a class  Exception handling

21 Pointcut Denotes a set of join points, e.g., execution(void HelloWorld.say(String)) execution(void HelloWorld.*(String)) execution(* *.*(..))

22 Advice Code that is attached to a pointcut and can be run: - before - after each join point in the pointcut.

23 Advice (cont’d) before() : execution (void HelloWorld.say(String)) { System.out.println(“Good day!”); } after() : execution (void HelloWorld.say(String)) { System.out.println(“Over!”); } + around: you will see it in “lab”

24 Semantics of Advices a HelloWord dispatch before after

25 How Does It Work? Aspect weaver combines classes and aspects  compiler / pre-processor / interpreter  unambiguously coordinates cross-cutting aspect weaver public class PrinterImpl { String status = “Idle” Vector jobs; public PrinterImpl() {} pubilc get_status() { return status } public add_job(int j) { jobs.add(j); } class Library { Hashtable books; Library(){ books = new Hashtable(100); } public Book getBook(User u, String title) { System.out.println("REQUEST TO GET BOOK " + title); if(books.containsKey(title)) { Book b = (Book)books.get(title); System.out.println("getBook: Found it:" + b); if (b != null) { if (b.get_borrower() == null) b.set_borrower(u); return b; } return null; } class User { private String name; Library theLibrary; Printer the; Printer public User(String n) { name = n; } public boolean getBook (String title) { Book aBook = theLibrary.getBook(this, title); thePrinter.print(this,aBook); return true; } class Book { private String title; private String author; private String isbn; private PostScript ps; private User borrower; public Book(String t, String a, String i, PostScript p) { title = t; author = a; isbn = i; ps = p; } public User get_borrower() {return borrower;} public void set_borrower(User u) {borrower = u;} public PostScript get_ps() { return ps; } } portal Printer { void print(Book book) { book: Book: {direct pages;} } portal Library { Book find (String title){ return: Book: {copy title, author, isbn;} } classes aspects executable code

26 Typical Uses of AOP Modularizing large programs (new behaves as the old code), e.g., exception handling in telecom code Modularizing to add new behavior (superimpose new behavior on old code), e.g., add authentication to a program Support of product lines (new code is a variant in some aspects), e.g., add code to control new airplane Support performance improvements (treat special cases faster), e.g., bypass code for unused network layers

27 Summary - Promise of AOP Modular separation of concerns Crosscutting concerns confined to single modules Thus systems are  Easier to understand,  Easier to change, adapt, evolve, and reuse Can add/remove spectators and change behavior without editing existing code.

28 Exercise Define an aspct to change the behavior of HelloWorld class to salute with “Sir,” before “say”ing anything. public class HelloWorld { public void say(String msg) { System.out.println(msg); } public static void main(String [] args) { new HelloWorld().say(“Hello, world!”); }

29 Exercise Given the following Java class, write AspectJ code that ignores every 10 th call to the setValue method. public class Counter { private int value; public void setValue(int value) { this.value = value; } public int getValue() { return value; }

30 Exercise (Take-Home) Given the following Java class, write AspectJ code that prints the old and the new values of the counter whenever the value is changed. public class Counter { private int value; public void setValue(int value) { this.value = value; } public int getValue() { return value; }

31 Around Advice Advice that is run as follows:  It is called before a join point  It can decide to proceed (delegate)  When the proceed returns, it can perform more actions

32 Around Advice (cont’d) void around() : execution (void HelloWorld.say(String)) { System.out.println(“Good day!”); if (Math.random() > 0.5) { proceed(); } System.out.println(“Over!”); }

33 Semantics of Around Advices a HelloWord dispatc h around

34 Aspects Similar to Java classes Units of modular crosscutting implementation, composed of pointcuts, advice, and ordinary Java member declarations. import java.io.*; public aspect MilitaryProtocol { pointcut sayPoint() : execution (void HelloWorld.say(String)); after() : sayPoint() { endMSG(System.out); } private void endMSG(PrintStream out) { out.println(END_OF_MSG); } private static final String END_OF_MSG = “Over!”; }