Presentation is loading. Please wait.

Presentation is loading. Please wait.

Aspect Oriented Programming Sumathie Sundaresan CS590 :: Summer 2007 June 30, 2007.

Similar presentations


Presentation on theme: "Aspect Oriented Programming Sumathie Sundaresan CS590 :: Summer 2007 June 30, 2007."— Presentation transcript:

1 Aspect Oriented Programming Sumathie Sundaresan CS590 :: Summer 2007 June 30, 2007

2 Background Procedural Languages like – Fortran, Pascal, C Object Oriented Programming like – Java, C++ Aspect Oriented Programming Frameworks like – AspectJ etc.

3 Advantages of OOP Modularity Reduce large problems to smaller Reusability Inheritance Polymorphism Reliability Robustness Maintainability Extendibility

4 Problems with OOP Not much strong reusability of code Every time inherit one base class Or Use delegation A functional unit can not be isolated, even they crosscut programs at many places Logging, security checks, transaction management Crosscutting concerns increases the cost of developing and maintenance cost.

5 Introduction Aspect Oriented Programming Was discovered in Palo Alto Research Center during 1980s and 1990s Is to Object Oriented Programming (like C++ to C)‏ Does not replace Object Oriented Programming technique, it complements it Is a technique Allows programmers to modularize the crosscutting concerns Separate crosscutting concerns from an application

6 Terminology Aspect Is a unit of modularity, encapsulation and abstraction Is like a class in object oriented technology Can be used to implement crosscutting concerns in a modular fashion Summarize behaviors that affect multiple classes into reusable modules Cross-cutting concerns Find out certain behavior to occur at one or more points in a program

7 Cont'd..... Join Points Identify the points in the execution of components where aspect should be applied For example: execution of method & constructor referred from www.cs.umd.edu

8 Cont'd..... Pointcuts Used to select join points Advice Specifies what to do at joint points For example Before(...) : PointcutExpr(...); After(...) : PointcutExpr(...); Around(...) : PointcutExpr(...); Weaving Task which is done by compiler in linking classes and aspect together Is no longer needed if there is an aspect oriented compiler available.

9 Example package hello; public class HelloWorld { public void sayHello() { System.out.println("Hello"); } public static void main(String[] args) { new HelloWorld().sayHello(); } public aspect World { pointcut greeting(): execution(* HelloWorld.sayHello(..)); after() returning: greeting() { System.out.println("World!"); } Advice Join Point

10 AOP tools in Java AspectJ(we are using this)‏ JBOSS AOP Spring AOP JAC

11 Installing AspectJ Command line Download AspectJ from aspectj.org Start the installation by running java-jar java –jar aspectj-1.5.3.jar Setup path and classpath Compile AspectJ programs by ajc YourJavaClass.java YourAspect.aj >ajc Hello.java World.aj Eclipse http://www.eclipse.org/ajdt/downloads/ Get the ajdt_1.4.1_for_eclipse_3.2 zip file Extract the zip file in to the eclipse folder http://www.eclipse.org/aspectj/doc/next/runtime- api/index.html http://www.eclipse.org/aspectj/doc/next/runtime- api/index.html

12 What is AJDT? “AspectJ Development Tools” Comprehensive tool support for using AspectJ in Eclipse Integrating the AspectJ compiler New editors/views/wizards for working with AspectJ artefacts Tool support is critical for AOP For day to day development of AO programs For learning AO concepts and understanding the power of AO

13 The outline view Shows aspect structure post compilation: – Advice – Inter-type declarations – Declared warnings/errors – Defined Pointcuts Useful feedback loop – Did my pointcut match anything? Fully navigable – Jump to advised locations

14 Source Annotations Gutter annotations in editor view – Highlight lines affected by advice – Hover help shows advice in affect – Context menu for annotations allows navigation to advice Important visual cue for developers – Not all users have the outline view active

15 Aspect Visualizer  Shows scattering, tangling, crosscutting  SeeSoft style  Optionally: Look at affect of particular aspects View at the package or class level Navigate from affected lines back to source Even zoom in !

16 Good Modularity: URL Pattern Matching URL pattern matching in org.apache.tomcat – red shows relevant lines of code – nicely fits in two boxes (using inheritance)‏

17 Problems: Logging is not modularized* instances of logging in org.apache.tomcat red represents lines of code that handle logging occurences are not in just one place, and in a significant number of places

18 Summary: Purpose of AOP AOP is an extension of OOP AOP does not replace OOP AOP has functions, classes and aspects Make design and code more modular Isolate the concerns for separate development Separate expression of behavioral concerns from structural ones Poor composition can lead to interference

19 The Future of AOP Language Design Standardization across frameworks Tool Development IDE support, UML support, aspect discovery, re-factoring, re-cutting, source level debuggers Dynamic Source Weaving (Wicca - debugs dynamically composed aspect- enabled programs)‏ Software Engineering Finding aspects that help define modularity in aspects Concern Manipulation Environment (CME) Open source Eclipse project targeting AO technologies Theory Consistency in varying compiler interpretation Fast compilation Advanced crosscut constructs

20 Thank you! Questions?


Download ppt "Aspect Oriented Programming Sumathie Sundaresan CS590 :: Summer 2007 June 30, 2007."

Similar presentations


Ads by Google