Your SlideShare is downloading. ×
0
Aop spring
Aop spring
Aop spring
Aop spring
Aop spring
Aop spring
Aop spring
Aop spring
Aop spring
Aop spring
Aop spring
Aop spring
Aop spring
Aop spring
Aop spring
Aop spring
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×
Saving this for later? Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime – even offline.
Text the download link to your phone
Standard text messaging rates apply

Aop spring

438

Published on

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

No Downloads
Views
Total Views
438
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
25
Comments
0
Likes
2
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide

Transcript

  • 1. AOP - Spring (Aspect Oriented Programming with Spring) Technical Knowledge Sharing Session 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. 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. 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. 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. <ul><li>AOP will separate the Crosscutting concerns from the System </li></ul>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. <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. <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. <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. <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. <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. 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. <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. 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. Thank you

×