问题 Code scattering Blocks of duplicated code Blocks of complementary code, and different modules implementing complementary parts of the concern Code.

Slides:



Advertisements
Similar presentations
Spring Transaction & Spring AOP
Advertisements

AspectWerkz 2 - and the road to AspectJ 5 Jonas Bonér Senior Software Engineer BEA Systems.
Aspect Oriented Programming. AOP Contents 1 Overview 2 Terminology 3 The Problem 4 The Solution 4 Join point models 5 Implementation 6 Terminology Review.
©Ian Sommerville 2006Software Engineering, 8th edition. Chapter 32 Slide 1 Aspect-oriented Software Development.
Aspect Oriented Programming - AspectJ Radhika Rajput.
Overview of AspectJ Aspect Oriented Software Development Seminar Technion presented by Oren Mishali.
Spring AOP Aspect Oriented Programming
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.
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;
CS 2511 Fall  Abstraction Abstract class Interfaces  Encapsulation Access Specifiers Data Hiding  Inheritance  Polymorphism.
Chapter 10 Classes Continued
AOP and Aspect C++ presentation by Igor Kotenkov based on presentation by Andreas Gal, Daniel Lohmann and Olaf Spinczyk.
Java Methods By J. W. Rider. Java Methods Modularity Declaring methods –Header, signature, prototype Static Void Local variables –this Return Reentrancy.
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.
Spring core v3.x Prepared by: Nhan Le. History v3.0 Spring Expression Language Java based bean metadata v3.1 Cache Abstraction Bean Definition Profile.
Aspect Oriented Programming Razieh Asadi University of Science & Technology Mazandran Babol Aspect Component Based Software Engineering (ACBSE)
PicoContainer Presented by: Jim O’Hara Ed Kausmeyer Jingming Zhang.
Aspect Oriented Programming Scott Nykl CSSE 411 Senior Seminar.
©Ian Sommerville 2006Software Engineering, 8th edition. Chapter 32 Slide 1 Aspect-oriented Software Development 1.
Modularizing Web Services Management with AOP María Agustina Cibrán, Bart Verheecke { Maria.Cibran, System and Software Engineering.
Inheritance. Introduction Inheritance is one of the cornerstones of object-oriented programming because it allows the creation of hierarchical classifications.
Aspect Oriented Programming Sumathie Sundaresan CS590 :: Summer 2007 June 30, 2007.
Spring Training 17/09/ Dependency Injection.
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.
A Meta-Level Specification and Profile for AspectJ in UML Joerg Evermann School of Information Management Victoria University of Wellington.
Methodology: The AOP Refactoring Process Aspect-Oriented Refactoring of the Apache Cocoon Shared-Object Resource Allocation System Jeff Dalton Advisor:
Design Rules for Increasing Modularity with CaesarJ Carlos Eduardo Pontual Advisor: Paulo Borba 17/06/2010.
A Presentation By V AIBHAV S AHARAN Web-enHanced Information Management COMS E6125.
AOP-1 Aspect Oriented Programming. AOP-2 Aspects of AOP and Related Tools Limitation of OO Separation of Concerns Aspect Oriented programming AspectJ.
Topic 1 Object Oriented Programming. 1-2 Objectives To review the concepts and terminology of object-oriented programming To discuss some features of.
Programming in Java CSCI-2220 Object Oriented Programming.
Features of AOP languages AOP languages have the following main elements: –a join point model (JPM) wrt base PL –a specification language for expressing.
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.
Introduction to Java Chapter 7 - Classes & Object-oriented Programming1 Chapter 7 Classes and Object-Oriented Programming.
Aspect Oriented Development Alex Beatty.  Purpose  Cross-cutting Concerns  Join Points, Pointcuts, and Advices  Weaving  Invasive vs. Non-Invasive.
1 Spring Framework April, 2012 Lam Ho Lam To. © 2010 Cisco and/or its affiliates. All rights reserved. Cisco Confidential 2 1.Spring Overview 2.Framework.
Copyright 2007 SpringSource. Copying, publishing or distributing without express written permission is prohibited. Spring AOP – Part 2 Advanced Aspect-Oriented.
Aspect Oriented Programming Adlux Consultancy Services Pvt Ltd
Kansas City Java User’s Group Jason W. Bedell July 12, 2006
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
CSC450 Software Engineering Devon M. Simmonds University of North Carolina, Wilmington 1.
5.1 Basics of defining and using classes A review of class and object definitions A class is a template or blueprint for an object A class defines.
L’origine dei mali: le dipendenze tra componenti Stefano Leli 14° Workshop DotNetMarche Venerdì 16 aprile
Creative Commons Attribution- NonCommercial-ShareAlike 2.5 License Sakai Programmer's Café Sakai Montreal CRIM Workshop Introduction to Spring Framework.
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.
Modern Programming Tools And Techniques-I
Topic: Classes and Objects
Chengyu Sun California State University, Los Angeles
Aspect-Oriented Programming with the Eclipse AspectJ plug-in
By Ru Shen Department of Computer Science UAlbany, 2008
Chengyu Sun California State University, Los Angeles
JAsCo an Aspect-Oriented approach tailored for
CS520 Web Programming Spring – Aspect Oriented Programming
AspectAda Aspect-Oriented Programming for Ada95
Leveraging ColdSpring To Make Better Applications
Aspect Oriented Programming
Presentation transcript:

问题 Code scattering Blocks of duplicated code Blocks of complementary code, and different modules implementing complementary parts of the concern Code tangling Code tangling occurs when a module has to manage several concerns at the same time such as logging, exception handling, security, caching, and more or when a module has elements of the implementation of other concerns inside.

AOP 面向对象 Aspect Class Joinpoint This is the application point of the aspect. It is a point of the execution of a program such as the invocation of a constructor or the execution of a method or the management of an exception (WHEN). Advice This is the action an aspect performs at a certain joinpoint. Advices can be "around", "before", and "after". Pointcut This is the expression for the joinpoint's selection, for instance a method's execution with a certain signature (WHERE)

AOP 面向对象 Introduction This is the declaration of methods or additional fields on the object to which the aspect will be applied. It allows the introduction of new interfaces and implementations on the objects. Target object This is the module (Object) to which the aspect will be applied. Weaving This is the linking action between the aspect and the objects to which advices must be applied

AOP 面向对象 Before advice After returning advice Throws advice After (finally) advice Around advice

the crosscutting concerns should be analysed as a third dimension of the design. In these situations, aspect-oriented programming provides support to object-oriented programming for uncoupling modules that implement crosscutting concerns.

 Spring XML 方式  AspectJ annotation 方式  Schema-based 配置方式

Spring permits only method execution to be used as a joinpoint. So we can't use with Spring AOP all the features of AOP, but we can do so with AspectJcalled by Spring. For example, we must use the support of AspectJif we want to use as a joinpoint:  The invocations of constructors  Access to the domains of objects with the setter and getter  The initialization of an object  The initialization of an object with a calling super()  The execution inside a class with this()  The calling of a method

 A pointcut is an expression for the selection of joinpoints. It can be a collection of joinpoints used to define an advice that has to be executed. Methods starting with a certain prefix (such as, getter and setter) Methods with a particular package (such as org.springaop.domain.*) Methods that return a certain kind of output (such as public MyClass get*(...)) A pointcut is the composition of a ClassFilter and a MethodMatcher.

 1. NameMatchMethodPointcut  2. RegexpMethodPointcut  3. StaticMethodMatcherPointcut  4. DynamicMethodMatcherPointcut  ComposablePointcut  ControlFlowPointcut

 public class NameMethodMatcherExample {  public static void main(String[] args) {  NameMethodTargetExample target = new NameMethodTargetExample();  NameMatchMethodPointcut pc = new NameMatchMethodPointcut();  pc.addMethodName("printSpot");  pc.addMethodName("printAction");  Advisor advisor = new DefaultPointcutAdvisor(pc, new AdviceExample());  ProxyFactory pf = new ProxyFactory();  pf.setTarget(target);  pf.addAdvisor(advisor);  NameMethodTargetExample proxy = (NameMethodTargetExample)pf.getProxy();  proxy.printName();  proxy.printAction();  proxy.printSpot();  }

 A joinpoint is a well-defined point during the execution of your application. Typical examples of joinpoints include a method call, method execution, class initialization, and object instantiation. Joinpoints are a core concept of AOP and define the points in your application at which you can insert additional logic using AOP.  Spring AOP only supports one joinpoint type— method invocation.

 An advice specifies what must be done at a joinpoint.  Spring uses a chain of interceptors to wrap the invocation of the method and apply to it the advices contained into this chain. As said before, Spring is consistent with the specifications of the AOP Alliance, but provides a slightly different programming model

 Before Advice  After Returning Advice  After throwing Advice

 The advisor isn't a concept from AOP in general, but is specific to Spring AOP.  The advisor links together pointcuts and advice. So it contains both the action to be executed (defined in the advice) and the point where it is to be executed (defined in the pointcut). The advisor's role is to decouple pointcuts and advice, in order to reuse them independently from each other.

 Introductions are a very strong component of the Spring AOP. They permit us to dynamically introduce new one-object functionalities as the implementation of interfaces on existing objects:  To create a mixin, adding to the state held in the object. This is probably the most important use.  To expose additional states associated with a special TargetSource. This is used within Spring, for example, with scripting support.  To expose an object or object graph in a different way—for example, making an object graph implement the XML DOM interfaces.

 a normal advice can be applied to any object since it has a per-class lifecycle,  an introduction has a per-instance lifecycle.

This allows us to focus our attention and development on crosscutting concerns to apply through the proxy, rather than focus on the proxy. setTarget: Specify the target object you want to proxy. setProxyTargetClass: The default behavior is the following:  If an interface is available, it's used as a JDK proxy.  If an interface is not available, it's used as a CGLIB proxy.  If we set the value to true, it's used as a CGLIB proxy.

 10/11/30/aop-postsharp.html 10/11/30/aop-postsharp.html