AOP - Spring  (Aspect Oriented Programming with Spring) Technical Knowledge Sharing  Session 2
<ul><li>Common Functionalities used across the application modules </li></ul><ul><li>Ex: </li></ul><ul><li>Transaction man...
public void withdraw(int amount){ balance = this.balance – amount;  accountDao.saveBalance(balance); } bankLogger.info(“Wi...
public void withdraw(int amount){ balance = this.balance – amount;  accountDao.saveBalance(balance); } public void deposit...
Transaction Management Logging public void withdraw(int amount){ balance = this.balance – amount;  accountDao.saveBalance(...
<ul><li>AOP will separate the Crosscutting concerns from the System </li></ul>What AOP Does?
withdraw deposit public void withdraw(int amount){ balance = this.balance – amount;  accountDao.saveBalance(balance); } pu...
<ul><li>Joinpoint  – Defines A Point During the Execution of a program. </li></ul><ul><li>  We can insert Additional logic...
<ul><li>Target object  - object being advised by one or more aspects. </li></ul><ul><li>AOP proxy  – Will manage the way o...
<ul><li>Action taken at a particular Joinpoint is called as an Advice </li></ul><ul><li>Defines  What  needs to be Applied...
<ul><li>Before advice  </li></ul><ul><li>After returning advice  </li></ul><ul><li>After advice </li></ul><ul><li>Around a...
<ul><li>Process of Applying Aspects to a Target Object. </li></ul><ul><li>Will Create a proxied Object. </li></ul>AOP Weav...
public class  CustomerImpl   implements  Customer { public void  browse (){ System.out.println(“ Browsing Internet ”); } }...
<ul><li>Output: </li></ul><ul><ul><ul><li>Login Time </li></ul></ul></ul><ul><ul><ul><li>Browsing Internet... </li></ul></...
Reference  <ul><li>Spring Documentation :  </li></ul><ul><li>Chapter 6. Aspect Oriented Programming with Spring </li></ul>...
Thank you
Upcoming SlideShare
Loading in …5
×

Aop spring

809 views

Published on

Published in: Technology, Real Estate
0 Comments
2 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
809
On SlideShare
0
From Embeds
0
Number of Embeds
2
Actions
Shares
0
Downloads
33
Comments
0
Likes
2
Embeds 0
No embeds

No notes for slide

Aop spring

  1. 1. AOP - Spring (Aspect Oriented Programming with Spring) Technical Knowledge Sharing Session 2
  2. 2. <ul><li>Common Functionalities used across the application modules </li></ul><ul><li>Ex: </li></ul><ul><li>Transaction management </li></ul><ul><li>Logging </li></ul><ul><li>Security </li></ul>Crosscutting Concerns
  3. 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 <ul><li>Eg: Banking Application </li></ul>Transaction Management Logging
  4. 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); } <ul><li>Coupling between Core & Crosscutting Concerns </li></ul><ul><li>Duplicate Code </li></ul><ul><li>Hard to maintain Code </li></ul>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. 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? <ul><li>You can modularize Crosscutting Concerns Using Spring – AOP </li></ul>txn.begin(); txn.commit(); txn.begin(); txn.commit(); bankLogger.info(“Withdraw - ” + amount); bankLogger.info(“Deposit - ” + amount);
  6. 6. <ul><li>AOP will separate the Crosscutting concerns from the System </li></ul>What AOP Does?
  7. 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. 8. <ul><li>Joinpoint – Defines A Point During the Execution of a program. </li></ul><ul><li> We can insert Additional logics at Joinpoints </li></ul><ul><li>Advice – Action taken at a Joinpoint. </li></ul><ul><li>Pointcut – Combination of Joinpoints where the Advice need to be Applied. </li></ul><ul><li>Aspect – a modularization of a Crosscutting concern. </li></ul>AOP Concepts
  9. 9. <ul><li>Target object - object being advised by one or more aspects. </li></ul><ul><li>AOP proxy – Will manage the way of Applying Aspects at particular Pointcuts. </li></ul>AOP Concepts Contd…
  10. 10. <ul><li>Action taken at a particular Joinpoint is called as an Advice </li></ul><ul><li>Defines What needs to be Applied and When </li></ul><ul><li>What – Functionality </li></ul><ul><li>When – Advice Type </li></ul><ul><li>Eg: Applying Logging Advice </li></ul>withdraw Advice
  11. 11. <ul><li>Before advice </li></ul><ul><li>After returning advice </li></ul><ul><li>After advice </li></ul><ul><li>Around advice </li></ul><ul><li>After throwing advice </li></ul>Method Method Method Method Method Exception Advice Types
  12. 12. <ul><li>Process of Applying Aspects to a Target Object. </li></ul><ul><li>Will Create a proxied Object. </li></ul>AOP Weaving Class Bank{ public void withdraw(int amnt); } Proxy Target Caller
  13. 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 ”); } } <ul><li>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. </li></ul>Example – Use of AOP with Spring
  14. 14. <ul><li>Output: </li></ul><ul><ul><ul><li>Login Time </li></ul></ul></ul><ul><ul><ul><li>Browsing Internet... </li></ul></ul></ul><ul><ul><ul><li>Logout Time </li></ul></ul></ul>Example – Use of AOP with Spring Browse CafeOwner.loginTime () CafeOwner.logoutTime () Before Advice After Advice Pointcut
  15. 15. Reference <ul><li>Spring Documentation : </li></ul><ul><li>Chapter 6. Aspect Oriented Programming with Spring </li></ul><ul><li>Spring In Action – Manning (Updated for Spring 3.0) </li></ul><ul><li>Video Tutorial – </li></ul><ul><li>Spring AOP Tutorial </li></ul>
  16. 16. Thank you

×