IoC & AOP Vu Cong Thanh Vi Quoc Hanh Social team
Agenda <ul><li>IoC - Introduction </li></ul><ul><li>IoC – Definition & Benefits </li></ul><ul><li>IoC – Concepts </li></ul...
Inversion Of Control (IoC)
IoC – Introduction - “Dependencies”
IoC – Introduction – Dependency Problems <ul><li>Code is  tightly coupled </li></ul><ul><li>Difficult to  isolate  when te...
IoC – Introduction - WITHOUT IoC <ul><li>Construction by Hand. </li></ul><ul><li>Factory Pattern. </li></ul>
IoC – Definition & Benefits <ul><li>Hollywood principle “Don't call us, we'll call you.”  </li></ul><ul><li>Creating ,  As...
IoC – Definition & Benefits <ul><li>Pros: </li></ul><ul><ul><li>Loosely Coupled </li></ul></ul><ul><ul><li>Increases Tesab...
IoC – Concepts – Time launcher <ul><li>Constructed and prepared  before it can be used. </li></ul><ul><ul><li>In the  init...
IoC – Concepts– Time launcher <ul><li>Constructed and prepared  before it can be used. </li></ul><ul><ul><li>On  demand , ...
IoC – Concepts – Metadata Configuration <ul><li>XML configuration file. </li></ul><ul><li>Annotations(@Injector, @Singleto...
IoC – Concepts - Scope <ul><li>Fixed  duration of time  or method calls in  which an object exist.  General-purpose scopes...
IoC - Concepts - Benefit of Scope <ul><li>Lets injector manage the  latent state  of your objects </li></ul><ul><li>Ensure...
Design your own IoC Source Code: Guice: google-guice.googlecode.com/svn/trunk/ Vbox: https://github.com/thanhvc/etk-vbox
Design your own IoC – Injector Diagram
Design your own IoC – Context Diagram
Design your own IoC – State Diagram Start Constructing Finish States: Constructing, Start and Finish http://www.slideshare...
Design your own IoC – State Diagram(Cont)
DEMO
Aspect Oriented Programming (AOP)
Agenda <ul><li>What is IOC? </li></ul><ul><li>IOC – Time of Injector </li></ul><ul><li>IOC – Pros & Cons </li></ul><ul><li...
INTRODUCTION - OOP <ul><li>A  set of objects  that interact with each other </li></ul>
INTRODUCTION - AOP <ul><li>View the system as a  set of concerns </li></ul>
INTRODUCTION – CONCERNS <ul><li>A particular  role ,  concept  or  area of interest </li></ul>
INTRODUCTION - CROSSCUTTING
INTRODUCTION - CROSSCUTTING CONCERNS <ul><li>System level requirements that  crosscut  many core module level requirements...
INTRODUCTION – CROSSCUTTING CONCERNS PROBLEMS <ul><li>Code  tangling , Code  scattering , Less code reuse, More difficult ...
AOP - DEFINITION <ul><li>Lets you implement  individual  concerns in a  loosely coupled  way and combine these implementat...
AOP - BENEFITS <ul><li>Modularized  implementation of crosscutting concerns  behavior in the code. </li></ul><ul><li>Easie...
AOP - BENEFITS <ul><li>Late binding of design decision  behavior in the code. </li></ul><ul><li>More  code reuse </li></ul>
AOP - CONCEPTS <ul><li>Aspect:  The  merger of advice and pointcuts . All information about  where ,  when  and  what  job...
AOP - CONCEPTS <ul><li>Target:  Object being advised. </li></ul><ul><li>Proxy:  The  object created  after applying advice...
AOP – HOW IT WORKS <ul><li>Decorator Pattern </li></ul><ul><li>Proxy Pattern  Control access to an object </li></ul><ul><l...
AOP – HOW IT WORKS
AOP – BEHIND THE SCENCES Aspect Object_B Object_A advice Object Oriented Flow Aspect Oriented Flow pointcut = method_B Tar...
AOP – ENGINES & FRAMEWORKS <ul><li>JDK </li></ul><ul><li>CGLIB  really create new class through bytecode manipulation  cod...
AOP vs OOP - CONCLUSION Object Oriented Aspect Oriented Class  – code unit that encapsulates methods and attributes. Aspec...
DEMO
Thank you!
Upcoming SlideShare
Loading in …5
×

AOP-IOC made by Vi Quoc Hanh and Vu Cong Thanh in SC Team

1,012 views
942 views

Published on

This presentation made by Vi Quoc Hanh and Vu Cong Thanh in SC Team from eXo Platform SEA.

Published in: Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
1,012
On SlideShare
0
From Embeds
0
Number of Embeds
31
Actions
Shares
0
Downloads
14
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

AOP-IOC made by Vi Quoc Hanh and Vu Cong Thanh in SC Team

  1. 1. IoC & AOP Vu Cong Thanh Vi Quoc Hanh Social team
  2. 2. Agenda <ul><li>IoC - Introduction </li></ul><ul><li>IoC – Definition & Benefits </li></ul><ul><li>IoC – Concepts </li></ul><ul><li>IoC – Design your own IoC. </li></ul><ul><li>Demo </li></ul><ul><li>AOP - Introduction </li></ul><ul><li>AOP - Definition & Benefits </li></ul><ul><li>AOP - Concepts </li></ul><ul><li>AOP - How it works? </li></ul><ul><li>Demo </li></ul>
  3. 3. Inversion Of Control (IoC)
  4. 4. IoC – Introduction - “Dependencies”
  5. 5. IoC – Introduction – Dependency Problems <ul><li>Code is tightly coupled </li></ul><ul><li>Difficult to isolate when testing </li></ul><ul><li>Difficult to maintain . </li></ul>
  6. 6. IoC – Introduction - WITHOUT IoC <ul><li>Construction by Hand. </li></ul><ul><li>Factory Pattern. </li></ul>
  7. 7. IoC – Definition & Benefits <ul><li>Hollywood principle “Don't call us, we'll call you.” </li></ul><ul><li>Creating , Assembling and Wiring the dependencies into Object graph. </li></ul><ul><li>Type of Dependency Injector: </li></ul><ul><ul><li>Constructor </li></ul></ul><ul><ul><li>Setter </li></ul></ul><ul><ul><li>Method </li></ul></ul><ul><ul><li>Field(Guice) </li></ul></ul>
  8. 8. IoC – Definition & Benefits <ul><li>Pros: </li></ul><ul><ul><li>Loosely Coupled </li></ul></ul><ul><ul><li>Increases Tesability </li></ul></ul><ul><ul><li>Separates component clearly. </li></ul></ul><ul><ul><li>Allows for use of Inversion of Control Container. </li></ul></ul><ul><li>Cons: </li></ul><ul><ul><li>Increases code complexity </li></ul></ul><ul><ul><li>Difficult to understand at First </li></ul></ul><ul><ul><li>Complicate Debugging at First </li></ul></ul><ul><ul><li>Complicates following Code Flow. </li></ul></ul>
  9. 9. IoC – Concepts – Time launcher <ul><li>Constructed and prepared before it can be used. </li></ul><ul><ul><li>In the init lifecycle stage of a web application. </li></ul></ul><ul><ul><li>On startup of a desktop program </li></ul></ul>
  10. 10. IoC – Concepts– Time launcher <ul><li>Constructed and prepared before it can be used. </li></ul><ul><ul><li>On demand , every time it is needed </li></ul></ul><ul><ul><li>Lazily , when it is first needed </li></ul></ul>
  11. 11. IoC – Concepts – Metadata Configuration <ul><li>XML configuration file. </li></ul><ul><li>Annotations(@Injector, @Singleton, …) </li></ul><ul><li>Invoking into a programmatic API. </li></ul>
  12. 12. IoC – Concepts - Scope <ul><li>Fixed duration of time or method calls in which an object exist. General-purpose scopes: Singleton and No-scope . </li></ul><ul><li>Web Application: </li></ul><ul><ul><li>Request , Session and Conversation scope </li></ul></ul><ul><ul><li>Transaction scope </li></ul></ul>
  13. 13. IoC - Concepts - Benefit of Scope <ul><li>Lets injector manage the latent state of your objects </li></ul><ul><li>Ensures that your services get new instances of dependencies as needed </li></ul><ul><li>Implicitly separates state by context. </li></ul>
  14. 14. Design your own IoC Source Code: Guice: google-guice.googlecode.com/svn/trunk/ Vbox: https://github.com/thanhvc/etk-vbox
  15. 15. Design your own IoC – Injector Diagram
  16. 16. Design your own IoC – Context Diagram
  17. 17. Design your own IoC – State Diagram Start Constructing Finish States: Constructing, Start and Finish http://www.slideshare.net/Thuy_Dang/regular-expression-made-by-to-minh-hoang-portal-team
  18. 18. Design your own IoC – State Diagram(Cont)
  19. 19. DEMO
  20. 20. Aspect Oriented Programming (AOP)
  21. 21. Agenda <ul><li>What is IOC? </li></ul><ul><li>IOC – Time of Injector </li></ul><ul><li>IOC – Pros & Cons </li></ul><ul><li>IOC - Scope </li></ul><ul><li>Demo </li></ul><ul><li>AOP - Introduction </li></ul><ul><li>AOP - Definition & Benefits </li></ul><ul><li>AOP - Concepts </li></ul><ul><li>AOP - How it works? </li></ul><ul><li>Demo </li></ul>
  22. 22. INTRODUCTION - OOP <ul><li>A set of objects that interact with each other </li></ul>
  23. 23. INTRODUCTION - AOP <ul><li>View the system as a set of concerns </li></ul>
  24. 24. INTRODUCTION – CONCERNS <ul><li>A particular role , concept or area of interest </li></ul>
  25. 25. INTRODUCTION - CROSSCUTTING
  26. 26. INTRODUCTION - CROSSCUTTING CONCERNS <ul><li>System level requirements that crosscut many core module level requirements </li></ul>
  27. 27. INTRODUCTION – CROSSCUTTING CONCERNS PROBLEMS <ul><li>Code tangling , Code scattering , Less code reuse, More difficult evolution... </li></ul><ul><li>Face problem in design when requirements growth </li></ul>
  28. 28. AOP - DEFINITION <ul><li>Lets you implement individual concerns in a loosely coupled way and combine these implementations to form the final system. </li></ul><ul><li>Complements object oriented programming. </li></ul><ul><li>Is not about “patching” pieces of code. About performing an action systematically upon recognition of a behavior in the code. behavior in the code. </li></ul>
  29. 29. AOP - BENEFITS <ul><li>Modularized implementation of crosscutting concerns behavior in the code. </li></ul><ul><li>Easier-to-evolve systems - extensibility behavior in the code. </li></ul>
  30. 30. AOP - BENEFITS <ul><li>Late binding of design decision behavior in the code. </li></ul><ul><li>More code reuse </li></ul>
  31. 31. AOP - CONCEPTS <ul><li>Aspect: The merger of advice and pointcuts . All information about where , when and what job is to be done. </li></ul><ul><li>Advice: The job of an aspect. Defines what and when of an aspect. </li></ul><ul><li>Pointcut: Pointcuts help narrow down the joinpoints advised by an aspect. Define the where of an aspect. </li></ul><ul><li>Jointpoint: A point in the execution of an application where an aspect can be plugged in. All the opportunities for advice to be applied. behavior in the code. </li></ul>
  32. 32. AOP - CONCEPTS <ul><li>Target: Object being advised. </li></ul><ul><li>Proxy: The object created after applying advice to the target object. </li></ul><ul><li>Weaving: Process of applying aspects to a target object to created a new proxied object code. </li></ul>
  33. 33. AOP – HOW IT WORKS <ul><li>Decorator Pattern </li></ul><ul><li>Proxy Pattern Control access to an object </li></ul><ul><li>Allows for object level access control by acting as a pass through entity or a placeholder object. co </li></ul><ul><li>d </li></ul><ul><li>. </li></ul>
  34. 34. AOP – HOW IT WORKS
  35. 35. AOP – BEHIND THE SCENCES Aspect Object_B Object_A advice Object Oriented Flow Aspect Oriented Flow pointcut = method_B Target Object = Object_B Weaving jointpoint = method invocation Object Oriented Flow
  36. 36. AOP – ENGINES & FRAMEWORKS <ul><li>JDK </li></ul><ul><li>CGLIB really create new class through bytecode manipulation code. </li></ul><ul><li>ASPECTJ </li></ul><ul><li>JBOSS AOP </li></ul><ul><li>SPRING FRAMEWORK c </li></ul><ul><li>… ........ ode. </li></ul>Engines Frameworks (Java)
  37. 37. AOP vs OOP - CONCLUSION Object Oriented Aspect Oriented Class – code unit that encapsulates methods and attributes. Aspect – code unit that encapsulates pointcuts, advice, and attributes. Method signatures – define the entry points for the execution of method bodies. Pointcut – define the set of entry points (triggers) in which advice is executed. Method bodies – implementations of the primary concerns. Advice – implementations of the cross cutting concerns. Compiler – converts source code into object code. Weaver – instruments code (source or object) with advice.
  38. 38. DEMO
  39. 39. Thank you!

×