Aspect Oriented Programming - PowerPoint PPT Presentation

1 / 38
About This Presentation
Title:

Aspect Oriented Programming

Description:

Definition - Points in a program's execution. ... 'pointcut' declares that what follows is a ... http://en.wikipedia.org/wiki/Aspect-oriented_programming ... – PowerPoint PPT presentation

Number of Views:54
Avg rating:3.0/5.0
Slides: 39
Provided by: stude1353
Category:

less

Transcript and Presenter's Notes

Title: Aspect Oriented Programming


1
Aspect Oriented Programming
  • Joel Ruisi

2
Aspect Oriented Programming
  • What is it?
  • Programming methodology that modularizes code
    into processes.
  • What does it do?
  • Aids programmers in the separation of
    concerns/processes, specifically cross-cutting
    concerns, as an advance in modularization.

3
Object Oriented Programming
  • Before we go any further, lets talk about
  • Object oriented programming methodology.
  • Concepts
  • Advantages
  • Disadvantages
  • Similarities between OOP and AOP.
  • Differences between OOP and AOP.
  • Why use AOP over OOP.

4
Object Oriented Programming
  • What is it?
  • Programming methodology that modularizes code
    into objects.
  • What does it do?
  • Aids programmers in separation of code into real
    world objects.

5
Object Oriented Programming
  • Components of OOP
  • Class
  • Component that modularizes code in OOP.
  • Function
  • Contained inside a class.
  • Performs a process.
  • Manipulates objects, attributes, etc.

6
Object Oriented Programming
  • Advantages of OOP.
  • Modularizes code into real world objects.
  • Easy to understand code.
  • Code is reusable if modularized correctly.
  • Code is easily maintained due to fix once, use
    everywhere principle.
  • Many development methodologies lend themselves to
    OOP.

7
Object Oriented Programming
  • Disadvantages of OOP.
  • Does not address cross-cutting concerns.
  • Processes/Functionality cross into many code
    modules.
  • Creates duplicate code if not addressed.
  • More on this later
  • Unaddressed cross-cutting concerns may be hard to
    maintain.

8
Object Oriented Programming
  • Similarities between AOP and OOP.
  • Take advantage of code modularization.
  • Code Reusability
  • Code Maintainability
  • Differences between AOP and OOP.
  • OOP modularizes on basis of real world objects.
  • AOP modularizes on basis of Processes/Functionalit
    ies.

9
Need for AOP
  • Problems with traditional Object Oriented
    Programming approach.
  • OOP divides processes into classes, or objects.
  • These classes often cross over into many
    different processes.
  • Leads to duplicated code.
  • Hard to maintain code.
  • Hard to use code.

10
Traditional OOP Approach
Fruit Shape Color Size
Oranges Storage Sell Buy
Bananas Storage Sell Buy
Apples Storage Sell Buy
Crosscutting Concerns
11
Need for AOP
  • Aspect Oriented Programming approach addresses
    cross cutting concerns.
  • Better separates processes (concerns) then
    previous approaches.
  • Creates cleaner code
  • Code is reusable at a greater extent then OOP
  • Properly separates business requirements into
    clean reusable code/

12
Need for AOP
13
AOP in Action
  • View system as set of concerns.
  • Divide complex system into manageable business
    processes.
  • Average system contains many concerns common
    across many processes.
  • Security
  • Data Manipulation
  • Business Logic
  • Logging

14
AOP in Action
  • Neglecting to identify cross cutting concerns can
    be devastating to system.
  • Code Tangling
  • Module in software accessing many different
    concerns/requirements.
  • Code Scattering
  • Requirement implementation scattered across many
    modules.
  • Other common problems
  • Less code reusability
  • Less maintainable code
  • Poor code quality

15
Advantage of AOP
  • Currently with OOP, implementation is forced on
    developer
  • Developer must implement requirements ahead of
    time.
  • Often time, developer is not clear on
    requirements up front.
  • Problem solved by AOP.
  • Implementation can be held off until clear.
  • Bad implementation is eliminated due to unclear
    requirements.

16
Basics of AOP
  • Basic steps of AOP implementation.
  • Modularize implementation of cross cutting
    concerns.
  • Implement cross cutting concerns in loosely
    coupled fashion.
  • Combine implementation to create completed system.

17
Technical Aspects of AOP
  • Major component of AOP is Aspect.
  • Equivalent to Class in Object Oriented
    Programming.
  • Puts pointcuts and advices together to form a
    crosscutting unit.
  • Use keyword aspect to signify that unit is an
    aspect, and not a class

18
Technical Aspects of AOP
  • Three major components of Aspect Oriented
    Programming.
  • Joinpoints
  • Pointcuts
  • Advice
  • These three components allow developer to take
    advantage of AOP theory.

19
Joinpoints
  • Definition - Points in a program's execution. For
    example, joinpoints could define calls to
    specific methods in a class.
  • Well-defined points in a program's execution.
  • Include calls to a method, a conditional check, a
    loop's beginning, or an assignment.

20
Pointcuts
  • Definition - Program constructs to designate
    joinpoints and collect specific context at those
    points.
  • Let you specify a joinpoint collection.
  • Let you expose context at the joinpoint to an
    advice implementation.

21
Example of Pointcut
  • pointcut callSayMessage() call(public static
    void HelloWorld.say(..))
  • States that when you call method that is public,
    static, void, from class HelloWorld, and method
    name starting with say, then call the point cut
    named callSayMessage.

22
Dissection of Pointcut Example
  • pointcut declares that what follows is a
    declaration of a named pointcut.
  • callSayMessage( ) is name of Pointcut.
  • call(public static void HelloWorld.say(..))
    captures needed joinpoints.
  • This joinput is when a call to class HelloWorld,
    with function starting with say.
  • call indicates the pointcut captures a call to
    the stated method name.
  • public static void HelloWorld.say(..) is the
    signature for methods to be captured.

23
Advices
  • Definition - Code that runs upon meeting certain
    conditions. For example, an advice could log a
    message before executing a joinpoint.
  • Specify the executable code when reaching certain
    pointcuts.
  • Three ways to associate an advice with a
    joinpoint before, after, and around a
    joinpoint's execution.

24
Example of Advice
  • before() call(public MyClass.(..))
    System.out.println("Before " thisJoinPoint "
    " System.currentTimeMillis()) after()
    call(public MyClass.(..)) System.out.println(
    "After " thisJoinPoint " "
    System.currentTimeMillis())

25
Example of Advice Dissected
  • Previous advice example prints thisJoinPoint and
    the current system time before and after calling
    any public method in MyClass.
  • before() prints out thisJoinPoint before any
    call to specified method.
  • after() prints out thisJoinPoint after any call
    to specified method.

26
AOP- Real World Application
  • Lets put this knowledge to use
  • Heres what will do
  • Set up case
  • Disect each requested application
  • Proceed with Object Oriented Approach
  • Differences and similarities with AOP approach
  • Proceed with Aspect Oriented Approach
  • Differences and similarities with OOP approach

27
AOP- Real World Application
  • Case set up
  • Need for three applications
  • Financial Application
  • Utilized in business processes pertaining to
    finances.
  • Involves employee interaction with financial
    processes
  • Timecard Application
  • Utilized in employee time keeping
  • Involves employee interaction with time keeping
    processes
  • Scheduling Application
  • Utilized in business processes pertaining to
    scheduling.
  • Involves employee interaction with event processes

28
Financial Application - OOP
  • Object Oriented Approach
  • Major objects in Financial Applications
  • FinancialObligation
  • Attributes
  • amount(double)
  • responsibleParty(ResponsibleParty)
  • repaid(boolean)
  • ResponsibleParty
  • Attributes
  • name(String)
  • location(String)
  • accountNumber(int)

29
Timecard Application - OOP
  • Object Oriented Approach
  • Major objects in Timecard Applications
  • Employee
  • Attributes
  • name(String)
  • employeeId(int)
  • TimeEntry
  • Attributes
  • employeeId(int)
  • time(Calendar)
  • amount(double)

30
Scheduling Application - OOP
  • Object Oriented Approach
  • Major objects in Scheduling Applications
  • Event
  • Attributes
  • time(Calendar)
  • eventId(int)
  • Participant
  • Attributes
  • name(String)
  • employeeId(int)

31
Aspect Oriented Approach
  • Aspect Oriented Approach to requested systems.
  • Initially, same objects as OOP approach used.
  • Before utilizing AOP, problems quickly evolve due
    to crosscutting concerns.
  • Common concerns are applicable to all three
    systems.

32
Common Crosscutting requirements
  • Financial, Timecard, Scheduling applications all
    have common requirements.
  • Transaction
  • All systems require transaction functionality
  • Security
  • All systems require security implementation
  • Login authentication
  • Content authorization

33
Common Crosscutting Requirements
  • What do these common requirements create?
  • Duplication of code
  • Harder to maintain
  • Harder to understand
  • Inconsistency of code
  • Not able to utilize the fix once use everywhere
    principle.

34
Fixing It With AOP
  • Create two new objects.
  • Instead of attaching security and transaction
    functionality to each object previously stated,
    create new objects.
  • Security object
  • Attributes
  • Login(String)
  • Password(String)
  • Verified(boolean)
  • Transaction
  • Attributes
  • User(String)
  • Type(String)
  • Cost(double)

35
Before AOP
Timecard Transaction Security
Scheduling Transaction Security
Financial Transaction Security
Crosscutting Concerns
36
After AOP
Timecard
Scheduling
Financial
Transaction
Security
37
Closing Thoughts
  • Important to remember that AOP is not replacing
    OOP, but enhancing it.
  • Can utilize OOP and AOP at same time.
  • AOP approach involves not only technical changes,
    but methodology changes.
  • Process oriented instead of Object oriented.
  • Any Questions???
  • No? Good!!!

38
References
  • Introduction to Aspect-Oriented Programming
  • http//www.onjava.com/pub/a/onjava/2004/01/14/aop.
    html?page1
  • Aspect-oriented programming
  • http//en.wikipedia.org/wiki/Aspect-oriented_progr
    amming
  • Learn AspectJ to better understand
    aspect-oriented programming
  • http//www.javaworld.com/javaworld/jw-03-2002/jw-0
    301-aspect2.html?page1
Write a Comment
User Comments (0)
About PowerShow.com