Aspect-Oriented Programming with the Eclipse AspectJ plug-in - PowerPoint PPT Presentation

About This Presentation
Title:

Aspect-Oriented Programming with the Eclipse AspectJ plug-in

Description:

Object-oriented programming provides a solution for business logic, but other ... { System.out.println('Goodbye!'); Introductions ... – PowerPoint PPT presentation

Number of Views:67
Avg rating:3.0/5.0
Slides: 15
Provided by: gall80
Learn more at: http://www.gallardo.org
Category:

less

Transcript and Presenter's Notes

Title: Aspect-Oriented Programming with the Eclipse AspectJ plug-in


1
Aspect-Oriented Programming with the Eclipse
AspectJ plug-in
  • David Gallardo

2
The problem
  • Object-oriented programming provides a solution
    for business logic, but other concerns complicate
    a clean OO design and implementation
  • Common services are often required
  • Logging
  • Authentication
  • Persistence
  • Instrumentation
  • Etc.
  • These requirements lead to code unrelated to the
    business being scattered throughout the
    application and are called crosscutting concerns.

3
Crosscutting concerns
4
The solution Aspect-Oriented Programming
  • Researchers at Xerox PARC start examining
    limitations of OOP in early 1990s
  • Separation of concerns is identified as the key
  • Crosscutting concerns are implemented separately
    as Aspects.
  • Aspects are the fundamental unit in AOP and are
    equivalent to a class in OOP.
  • Aspects interact with an application at
    interesting and pre-defined points in its
    execution such as method calls and field
    assignments. These are called join points.

5
Programming in AOP
  • Decompose application into separate business and
    crosscutting concerns
  • Implement concerns as classes and aspects
  • Recompose business and crosscutting logic using
    an AOP compiler. This process is called weaving
    and the compiler that performs this is called a
    weaver.

6
AspectJ The first AOP language
  • Xerox PARC researchers develop AspectJ, the first
    AOP language.
  • AspectJ is a simple, well-integrated extension of
    Java
  • It was given to the Eclipse Consortium in early
    2002
  • Available on the Eclipse.org website

7
Installing the Eclipse AspectJ plug-in
  • Available for 3.1. from the update site
  • http//download.eclipse.org/technology/ajdt/31/de
    v/update
  • Works in conjunction with Eclipses Java
    development tools.
  • This provides a source-to-bytecode weaver, based
    on the Eclipse Java compiler.
  • Plus views and perspectives that support for AOP
    programming.

8
Creating an aspect
  • You create an aspect in Eclipse pretty much like
    you do a class
  • Create an AspectJ project for it to live
  • Use the New wizard and select Aspect.
  • Youll get something that looks like this

public aspect Example
  • If you named your aspect Example, it will be in a
    file named (by default) Example.aj

9
Identifying join points with a pointcut
  • A joint point or a set of joint points is
    identified with a pointcut expression.
  • A pointcut uses patterns and wildcards that match
    type, name and method parameters.
  • The following identifies calls to public methods
    of type void that begin with the letters say

pointcut talk() call(public void say(..))
  • The following identifies all public getter
    methods that return an int or a long

pointcut access() call(int get(..))
call(long get(..))
10
Giving advice
  • Pointcuts only identify where an aspect should
    introduce behavior. They need to be associated
    with advicea code bodyin order to do anything.
  • Advice can run before or after a join point.
  • Advice can also run around a join point. Advice
    of this type can affect the execution of the join
    pointexecuting it conditionally, or, in the case
    of a method call, modifying the parameters.

11
Examples of advice
  • Here are some examples of advice for the pointcut
    talk from two slides ago

before() talk() System.out.println("Hello!"
) after() talk() System.out.println("Good
bye!")

12
Introductions
  • One more AspectJ feature can be included in an
    aspect, an introduction, or inter-type
    declaration.
  • This allows the aspect to alter classes by adding
    fields or methods, altering class heirarchy, etc.
  • We wont be using these here.

13
Eclipse AspectJ support
  • Decorators in the editor view identify which
    methods and fields in a class have advice
    associated with them.
  • Cross References view provides details about
    advice are associated with each method or field,
    or methods or fields associate with each advice.
  • Aspect Visualization perspectives shows
    graphically which class is affected by each
    aspect.
  • Debugging support is extended to advice.

14
Eclipse AspectJ demo
  • Demonstrate how to install using Update
  • Create an Aspect Project
  • Create a class and an aspect and run
  • Demonstrate editor support, outline,
    cross-reference.
  • Demonstrate Aspect Visualization perspective with
    Eclipse-provided example
Write a Comment
User Comments (0)
About PowerShow.com