Aop spring
Upcoming SlideShare
Loading in...5
×
 

Like this? Share it with your network

Share

Aop spring

on

  • 576 views

 

Statistics

Views

Total Views
576
Views on SlideShare
576
Embed Views
0

Actions

Likes
0
Downloads
20
Comments
0

0 Embeds 0

No embeds

Accessibility

Categories

Upload Details

Uploaded via as Microsoft PowerPoint

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

Aop spring Presentation Transcript

  • 1. AOP - Spring (Aspect Oriented Programming with Spring) Technical Knowledge Sharing Session 2
  • 2.
    • Common Functionalities used across the application modules
    • Ex:
    • Transaction management
    • Logging
    • Security
    Crosscutting Concerns
  • 3. public void withdraw(int amount){ balance = this.balance – amount; accountDao.saveBalance(balance); } bankLogger.info(“Withdraw - ” + amount); txn.begin(); txn.commit(); public void deposit(int amount){ balance = this.balance + amount; accountDao.saveBalance(balance); } bankLogger.info(“Deposit - ” + amount); txn.begin(); txn.commit(); Crosscutting Concerns
    • Eg: Banking Application
    Transaction Management Logging
  • 4. public void withdraw(int amount){ balance = this.balance – amount; accountDao.saveBalance(balance); } public void deposit(int amount){ balance = this.balance + amount; accountDao.saveBalance(balance); }
    • Coupling between Core & Crosscutting Concerns
    • Duplicate Code
    • Hard to maintain Code
    Why Worrying about Crosscutting Concerns? Logging bankLogger.info(“Withdraw - ” + amount); bankLogger.info(“Deposit - ” + amount); Transaction Management txn.begin(); txn.commit(); txn.begin(); txn.commit();
  • 5. Transaction Management Logging public void withdraw(int amount){ balance = this.balance – amount; accountDao.saveBalance(balance); } public void deposit(int amount){ balance = this.balance + amount; accountDao.saveBalance(balance); } Any solution for Crosscutting Concerns?
    • You can modularize Crosscutting Concerns Using Spring – AOP
    txn.begin(); txn.commit(); txn.begin(); txn.commit(); bankLogger.info(“Withdraw - ” + amount); bankLogger.info(“Deposit - ” + amount);
  • 6.
    • AOP will separate the Crosscutting concerns from the System
    What AOP Does?
  • 7. withdraw deposit public void withdraw(int amount){ balance = this.balance – amount; accountDao.saveBalance(balance); } public void deposit(int amount){ balance = this.balance + amount; accountDao.saveBalance(balance); } Joinpoint Applying AOP Logging Transaction Management Advise
  • 8.
    • Joinpoint – Defines A Point During the Execution of a program.
    • We can insert Additional logics at Joinpoints
    • Advice – Action taken at a Joinpoint.
    • Pointcut – Combination of Joinpoints where the Advice need to be Applied.
    • Aspect – a modularization of a Crosscutting concern.
    AOP Concepts
  • 9.
    • Target object - object being advised by one or more aspects.
    • AOP proxy – Will manage the way of Applying Aspects at particular Pointcuts.
    AOP Concepts Contd…
  • 10.
    • Action taken at a particular Joinpoint is called as an Advice
    • Defines What needs to be Applied and When
    • What – Functionality
    • When – Advice Type
    • Eg: Applying Logging Advice
    withdraw Advice
  • 11.
    • Before advice
    • After returning advice
    • After advice
    • Around advice
    • After throwing advice
    Method Method Method Method Method Exception Advice Types
  • 12.
    • Process of Applying Aspects to a Target Object.
    • Will Create a proxied Object.
    AOP Weaving Class Bank{ public void withdraw(int amnt); } Proxy Target Caller
  • 13. public class CustomerImpl implements Customer { public void browse (){ System.out.println(“ Browsing Internet ”); } } public class CafeOwner { public void loginTime (){ System.out.println(“ Login Time ”); } public void logoutTime (){ System.out.println(“ Logout Time ”); } public void issueBill (){ System.out.println(“ Calculate and issue the usage Bill ”); } }
    • An Internet café owner wants a system to Issue an Usage bill and track the Login and Logout times at the end of Browsing Internet by A Customer.
    Example – Use of AOP with Spring
  • 14.
    • Output:
        • Login Time
        • Browsing Internet...
        • Logout Time
    Example – Use of AOP with Spring Browse CafeOwner.loginTime () CafeOwner.logoutTime () Before Advice After Advice Pointcut
  • 15. Reference
    • Spring Documentation :
    • Chapter 6. Aspect Oriented Programming with Spring
    • Spring In Action – Manning (Updated for Spring 3.0)
    • Video Tutorial –
    • Spring AOP Tutorial
  • 16. Thank you