AOP: Aspect Oriented Programming
Here is the summary of my presentation that I did earlier this evening at Kansas City Java User’s Group.
Aspect Oriented Programming & Aspect J 101
Agenda
- What is AOP?
- OOP and AOP
- Definitions, buzz words
- Aspect J
- Demo
Introduction
- Programming Methodologies: Past & Present
- Concerns: Core & secondary concerns
- Matching Concerns & Methodology: Flexiblility with Quality
Modularization
- is the key Eg: EJB
- OOP: Good at modularizing core concerns. Eg: Interfaces & Classes but lacks in addressing peripheral concerns effectively.
How to indentify non-modular systems?
- Code Tangling
- Code Scattering
AOP
- AOP allows us to dynamically modify our static model to include the code required to fulfill the secondary requirements without having to modify the original static model
Examples Of Aspects
- Development Aspects: Logging, Tracing, Debugging, Profiling, etc.,
- Production Aspects: Performance Monitoring, Notifications, Security, Error Handling
AOP Process
- Aspectual Decomposition: Identify core & cross cutting concerns
- Concern Implementation: Implement concerns independently
- Aspectual Recomposition: Create Aspects
Benefits of AOP
- Higher and cleaner level of modularization
- Easier System Evolution
- More code reuse
Buzz Words
- Crosscutting: Concerns spanning multiple modules. Static & Dynamic
- Join Point: A well-defined point in the program flow. Method, Constructor, Field Access, Exception Handler, Class Initialization, Object Initialization
- Pointcut: Collection of Join Points and values at those points
- Advice: Piece of code executed at a Join Point
- Introduction: Introducing change to static model
- Aspects: It consists of: Point Cuts, Join Point, Advice.
- Scattering: Similar code distributed throughout many files/programs
- Tangling: Two or more concerns implemented in the same body of code.
- Weaving: Compile time Weaving & Runtime Weaving
Pointcuts
- Definition: Collection of Join Points and values at those points
- Example: [accessspecifier] pointcut pointcutname([args]) : pointcut-definition
Advice
- Definition: Piece of code executed at a Join Point
- Types: before, after and around.
Java Implementation of AOP
There were two prominent schools of thoughts.
- AspectJ: a general-purpose aspect-oriented extension to Java
- AspectWerkz: Simple, high-performant, dynamic, lightweight and powerful AOP for Java
AspectJ is
- a seamless aspect-oriented extension to the Java programming language
- Java platform compatible
- easy to learn and use
AspectJ enables
- clean modularization of crosscutting concerns, such as error checking and handling, synchronization, context-sensitive behavior, performance optimizations, monitoring and logging, debugging support, and multi-object protocols
References:
- AspectJ at Eclipse: http://eclipse.org/aspectj/
- Aspectwertz: http://aspectwerkz.codehaus.org/