Aspect Oriented Programming

Slides:



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

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.
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.
ASPECT ORIENTED SOFTWARE DEVELOPMENT Prepared By: Ebru Doğan.
OOP in Java Nelson Padua-Perez Chau-Wen Tseng Department of Computer Science University of Maryland, College Park.
University of British Columbia Software Practices Lab CAS Seminar 06 Fluid AJ - A Simple Fluid AOP Tool Terry Hon Gregor Kiczales.
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.
Programming Languages and Paradigms Object-Oriented Programming.
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.
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 Institute of Computer Software Nanjing University 1.
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.
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.
Aspect Oriented Programming Sumathie Sundaresan CS590 :: Summer 2007 June 30, 2007.
Aspect Oriented Programming Gülşah KARADUMAN.
Joel Phinney March 31, ◦ Concerns  Separation of Concerns, Tangled and Scattered Concerns, Cross-Cutting Concerns, Aspects ◦ Aspect-Oriented Software.
Methodology: The AOP Refactoring Process Aspect-Oriented Refactoring of the Apache Cocoon Shared-Object Resource Allocation System Jeff Dalton Advisor:
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.
1 An Aspect-Oriented Implementation Method Sérgio Soares CIn – UFPE Orientador: Paulo Borba.
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.
Topics for exam in AOSD Basic concepts: tangling, scattering, joinpoint, advice, cross-cutting, weaving AspectJ: syntax, pointcut notations, around, proceed,
Demeter Aspects We study techniques for the emerging area of Aspect-Oriented Software Development and focus on the following areas:  Aspectual Collaborations.
Chapter 8: Aspect Oriented Programming Omar Meqdadi SE 3860 Lecture 8 Department of Computer Science and Software Engineering University of Wisconsin-Platteville.
Alloy-based Lightweight Verification for Aspect-oriented Architecture Naoyasu Ubayashi(Kyushu Institute of Technology) Yuki Sato(Kyushu Institute of Technology)
© FPT SOFTWARE – TRAINING MATERIAL – Internal use 04e-BM/NS/HDCV/FSOFT v2/3 JSP Application Models.
Aspect Oriented Programming Adlux Consultancy Services Pvt Ltd
Kansas City Java User’s Group Jason W. Bedell July 12, 2006
问题 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
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)
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.
Leveraging ColdSpring to build a robust Flex applications Chris Scott, Cynergy Systems.
Sung-Dong Kim, Dept. of Computer Engineering, Hansung University Java - Introduction.
Software Engineering Lecture 7
An Interface Mechanism for Encapsulating Weaving in Class-based AOP
Chapter 1 Introduction to Computers, Programs, and Java
Introduction to Advanced Java Programming
Aspect-Oriented Programming with the Eclipse AspectJ plug-in
Chapter 3: Using Methods, Classes, and Objects
Discussion with Gregor Kiczales at UBC
Object-Orientated Programming
Demeter Aspects Who We Are Aspectual Collaborations
Aspect-Oriented Programming
Advanced Programming Behnam Hatami Fall 2017.
A Brief Introduction to Aspect-Oriented Programming
Aspect-oriented programming
AspectAda Aspect-Oriented Programming for Ada95
Aspect Oriented Software Design
Presentation transcript:

Aspect Oriented Programming 面向方面的编程 Institute of Computer Software Nanjing University 2018/12/2

摘要 Background and Motivation AOP AspectJ Summary Institute of Computer Software Nanjing University 2018/12/2

摘要 Background and Motivation AOP AspectJ Summary Institute of Computer Software Nanjing University 2018/12/2

Background and Motivation Where OOP has brought us Reusability of components Modularity Less complex implementation Reduced cost of maintenance …… Modularity is a universal advancement over structured programming that leads to clearer and better understood software Institute of Computer Software Nanjing University 2018/12/2

Red shows relevant lines of code Modularity in Reality Code from org.apache.tomcat Red shows relevant lines of code XML Parsing Good Modularity Nicely fits in one box Institute of Computer Software Nanjing University 2018/12/2

Pretty Good Modularity Modularity in Reality fits in two boxes URL pattern matching Pretty Good Modularity Institute of Computer Software Nanjing University 2018/12/2

Code tangling and scattering Modularity in Reality Red shows lines of code that handle logging Code tangling and scattering Logging Bad Modularity Not even in a small number of places Not in just one place Institute of Computer Software Nanjing University 2018/12/2

History of Programming Paradigms In the beginning: Programming in whichever way. Monolithic programs Institute of Computer Software Nanjing University 2018/12/2

History of Programming Paradigms Structured Programming Functional decomposition Modularity Institute of Computer Software Nanjing University 2018/12/2

History of Programming Paradigms Object-Oriented Programming Encapsulation & Inheritance Modularity Institute of Computer Software Nanjing University 2018/12/2

Nice things of OOP Modular structure Reuse Class Design patterns Framework Institute of Computer Software Nanjing University 2018/12/2

Some things cannot be modeled well in object hierarchies!! Limitations of OOP Some things cannot be modeled well in object hierarchies!! Institute of Computer Software Nanjing University 2018/12/2

A motivating example: Tracing class Point{ void set (int x, int y){ TraceSupport.traceEntry(“Point.set”); this.x =x; this.y=y; TraceSupport.traceExit(“Point.set”); } Institute of Computer Software Nanjing University 2018/12/2

Java API Example Same code repeated 16 times in java.io.File package java.io; public class File implements java.io.Serializable{ private String path; … public boolean exists(){ SecurityManager security = System.getSecurityManager(); if(security!=null){ security.checkRead(path); } return exits0(); public boolean canRead(){ return canRead0(); Same code repeated 16 times in java.io.File Institute of Computer Software Nanjing University 2018/12/2

Crossing cutting concerns Institute of Computer Software Nanjing University 2018/12/2

What is a concern? A particular goal, concept, or area of interest (requirement) A software system contains: Business (application) logic concerns System-level concerns Institute of Computer Software Nanjing University 2018/12/2

Crosscutting Concerns Crosscutting is how to characterize a concern than spans multiple units of OO modularity Crosscutting concerns resist modularization using normal OO construct Institute of Computer Software Nnjing University 2018/12/2

Separation of Concerns (SoC) Object-Oriented Programming separates and encapsulates some concerns Others end up tangled and scattered Basic problem N dimensions of concerns 1 dimension of implementation structure Tyranny decomposition Institute of Computer Software Nanjing University 2018/12/2

Approaches to SoC Composition Filters Multi-dimensional Separation of Concerns Adaptive Programming Aspect-Oriented Programming Was developed at Xerox PARC (施乐公司 帕洛阿尔托研究中心) (Related) Meta-Object Protocol (MOP) Reflective programming, meta-object protocol Institute of Computer Software Nanjing University 2018/12/2

摘要 Background and Motivation AOP AspectJ Summary Institute of Computer Software Nanjing University 2018/12/2

The AOP Idea Many cross-cuts aren’t random! They serve specific purposes They have well-defined structure So…let’s capture the cross-cutting structure in a modular way to better support for “Separation of Concerns” Institute of Computer Software Nanjing University 2018/12/2

Two central problems AOP tries to solve Code tangling One module, many concerns Code scattering One concern, many modules Example: logging Institute of Computer Software Nanjing University 2018/12/2

Two central problems AOP tries to solve Institute of Computer Software Nanjing University 2018/12/2

AOP approach to SoC Institute of Computer Software 2018/12/2 Nanjing University 2018/12/2

Prism Analogy Crosscutting concerns Implement each concern separately Weave concerns together Crosscutting concerns Institute of Computer Software Nanjing University 2018/12/2

Basic Mechanisms of AOP Aspect Advice Pointcut Weaving Institute of Computer Software Nanjing University 2018/12/2

Summary so far AOP is a software development technique that complements and extends OOP Provides new and powerful ways to modularize “crosscutting concerns” Crosscutting concerns: Behavior that cuts across class boundaries AspectJ is the leading implementation of AOP that extends Java’s OOP model Institute of Computer Software Nanjing University 2018/12/2

摘要 Background and Motivation AOP AspectJ Summary Institute of Computer Software Nanjing University 2018/12/2

What is AspectJ? A simple and practical aspect-oriented extension to Java A general purpose AO language Based on over ten years of research at Xerox PARC http://www.parc.com/research/projects/aspectj/default.html Launched in 1998 Transferred to Eclipse.org in 2002 http://www.eclipse.org/aspectj/ Latest version: AspectJ 1.6.12 2018/12/2

Design assumptions Real Community Users Java compatibility Writing aspects Reading aspects Idioms How effective for concerns Modular, reusable and easy to develop and maintain Java compatibility Upward compatibility Platform compatibility Tool compatibility Programmer Compatibility Institute of Computer Software Nanjing University 2018/12/2

AspectJ Compilation Process Application modules .java or jar files Application System weaving ajc: javac extension Aspects .aj files Institute of Computer Software Nanjing University 2018/12/2

Dynamic VS Static crosscutting Dynamic crosscutting define additional behavior to run at certain well- defined points in the execution of the program Static crosscutting modify the static structure of a program (e.g., adding new methods, implementing new interfaces, modifying the class hierarchy) Institute of Computer Software Nanjing University 2018/12/2

Concepts in AspectJ Join Points 连接点 Pointcut 切入点 Advice 通知 Aspect 方面 Introduce 引入 Institute of Computer Software Nanjing University 2018/12/2

High level View of AspectJ Advice advice body pointcut join point Java Program Institute of Computer Software Nanjing University 2018/12/2

Join Points Model Join point is a well-defined point in a program’s execution Method call: public void move(int dx, int dy){ setX(_x+dx); setY(_y+dy); } Method call join point Institute of Computer Software Nanjing University 2018/12/2

More Join Points public void setX(int x){ _x = x; } Method execution join point Field set join point Institute of Computer Software Nanjing University 2018/12/2

All Join Points method & constructor execution method & constructor call field get & set exception handler execution static & dynamic initialization dynamic joinpoints (cflow, cflowbelow) Institute of Computer Software Nanjing University 2018/12/2

Pointcuts Pointcut: Predicate on join points: selecting a collection of joinpoints Example: call (void Point.setX(int)) Wildcard characters are allowed. The following pointcut matches any method call to the methods of the class Point whose names begin with “set” call (void myPackage..*Point.set*()); Institute of Computer Software Nanjing University 2018/12/2

Executions of methods with the specified sig. Named Pointcuts Can be a Named set of join points Capture all the executions of the <void Point.setX(int)> or <void Point.setY(int)> method Name and parameters Executions of methods with the specified sig. pointcut move(): execution (void Point.setX(int)) || execution (void Point.setY(int)); or Institute of Computer Software Nanjing University 2018/12/2

More on Pointcuts Basic pointcuts and pointcuts composition Pointcuts can be composed as boolean expressions with “&&”, “||” and “!” Pointcuts can have arguments Institute of Computer Software Nanjing University 2018/12/2

Pointcut Designators call, execution (method or constructor) get, set (field) within (type), withincode(method or constructor) this, target (type or id) args(type or id list) cflow, cflowbelow(pointcut) handler, throwing (exception type) combine with ||, && and ! use *, + and .. wildcards bind arguments (autoboxing!), this, target

Advice Code that runs before, after, or around (instead of) a join point Type of advice Pointcut it applies to after() returning(): move() { //code here runs after each move } Institute of Computer Software Nanjing University 2018/12/2

Advice Types in AspectJ Before advice: runs at the moment join point is reached, before method runs After advice: runs at the moment control returns through join point, just after method After, after returning, after throwing Around advice: runs when join point is reached and has control over whether method itself runs at all Institute of Computer Software Nanjing University 2018/12/2

Aspects Example: Aspect HistoryUpdating{ pointcut move(): execution(voidPoint.setX(int)) || execution(voidPoint.setY(int)); after() returning: move() { //code here runs after each move } Institute of Computer Software Nanjing University 2018/12/2

Aspects Mix everything we’ve seen up to now and put it one or more modular units called Aspects. Looks a lot like a class! Can contain pointcuts, advice declarations, methods, variables …. Institute of Computer Software Nanjing University 2018/12/2

How it works Short answer: bytecode modification Institute of Computer Software Nanjing University 2018/12/2

A first example Institute of Computer Software 2018/12/2 Nanjing University 2018/12/2

What it does Sample Code Institute of Computer Software 2018/12/2 Nanjing University 2018/12/2

AspectJ’s Introductions An introduction is an aspect member that allows to Add methods to an existing class Add field to an existing class Extend an existing class with another Implement an interface in an existing class Convert checked exceptions into unchecked exceptions Institute of Computer Software Nanjing University 2018/12/2

Introduction examples public int foo.bar(int x); private int foo.counter; declare parents: mammal extends animal; declare parents: MyThread implements MyThreadInterface; Institute of Computer Software Nanjing University 2018/12/2

Some Advanced Topics Aspect Extension (Inheritance) example Institute of Computer Software Nanjing University 2018/12/2

Some Advanced Topics Aspect Creation (Association) Aspect instance Single (static) vs. Multiple (dynamic) Default: Singleton, created when program begins Object (Class) association: perthis, pertarget Controlflow association Percflow, percflowbelow Aspect & Advice Precedence & Interactions Institute of Computer Software Nanjing University 2018/12/2

Performance impact See “Advice Weaving in AspectJ” “The implementation of advice weaving introduces very little performance overhead when compared to the same functionality coded by hand.” Does make it easy to create performance destroying code… But allows powerful optimizations Institute of Computer Software Nanjing University 2018/12/2

AspectJ Terminology a join point is a well-defined point in the program flow a pointcut is a group of join points advice is code that is executed at a pointcut introduction modifies the members of a class and the relationships between classes a compile time declaration introduces a compile time warning or error upon detection of certain usage patterns an aspect is a module for handling crosscutting concerns Aspects are defined in terms of pointcuts, advice, and introduction Aspects are reusable and inheritable Institute of Computer Software Nanjing University 2018/12/2

Dynamic AOP Systems Creating aspects at run-time Specifying pointcuts at run-time Dynamic code translation (or some special feature of the run-time environment) Enabling/disabling aspects at run-time Pointcuts are dynamic: it can be decided only at run-time whether advices have to be executed or not (based on run-time values, call-stack, etc.) Institute of Computer Software Nanjing University 2018/12/2

Other Java AOP sightings AspectWerkz: load-time/run-time weaving, AOP constructs defined using javadoctags BEA: AOP framework for Weblogic JBoss AOP framework AOP with interceptors Spring framework Limited AOP with proxies J2EE without EJB AspectJ2EE JasCo … Institute of Computer Software Nanjing University 2018/12/2

Other Aspect-Oriented Languages AspectC AspectC++ Aspect.Net Lightweight Python AOP AspectL(Lisp) AspectML AspectPHP Institute of Computer Software Nanjing University 2018/12/2

Middleware & System Level Applications Security Transaction Persistence Mobility Realtime& Embedded Systems OS …… Institute of Computer Software Nanjing University 2018/12/2

AOSD AOSD is a promising approach to encapsulate and modularize crosscutting concerns AOSD is not a substitute of the OO paradigm but an extension to it. Institute of Computer Software Nanjing University 2018/12/2

AOSD Institute of Computer Software Nanjing University 2018/12/2

A fast development area AOP Aspect-Oriented Programming AOSD Aspect-Oriented Software Design (Development) AORE (AOR) Aspect-Oriented Requirements Engineering AOM Aspect Oriented Modeling Institute of Computer Software Nanjing University 2018/12/2

Where to Get More Information The AspectJ website http://eclipse.org/aspectj AOSD website http://www.aosd.net Books Mastering AspectJ AspectJ in Action Google  Institute of Computer Software Nanjing University 2018/12/2

作业(本次作业不用提交) 运行demo程序,研究AspectJ的语法、编译过程 思考为什么说AOP不会取代OOP,而是对OOP 的补充? Institute of Computer Software Nanjing University 2018/12/2