Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

IOC and AOP presentation

519 views

Published on

Published in: Technology
  • Be the first to comment

IOC and AOP presentation

  1. 1. A O P & IO C V u Co n g T h a n h V i Qu o c Ha n h Social team www.exoplatform.com Copyright 2011 eXo Platform
  2. 2. Agenda W h a t is IO C ? IO C – Tim e o f In je c t o r IO C – P r o s & C o n s IO C - S c o p e De mo www.exoplatform.com 2 Copyright 2011 eXo Platform
  3. 3. In v e r s io n O fC o n t r o l ( IO C ) www.exoplatform.com Copyright 2011 eXo Platform
  4. 4. WHAT IS “DEPENDENCY”? www.exoplatform.com 4 Copyright 2011 eXo Platform
  5. 5. Implementation with NOT IOC» Construction by Hand.» Factory Pattern. www.exoplatform.com 5 Copyright 2011 eXo Platform
  6. 6. Dependencies Problems» Code is tightly coupled» Difficult to isolate when testing» Difficult to maintain. www.exoplatform.com 6 Copyright 2011 eXo Platform
  7. 7. What is IOC?» Hollywood principle “Dont call us, well call you.”» Creating, Assembling and Wiring the dependencies into Object graph.» Type of Dependency Injector: – Constructor – Setter – Method – Field(Guice) www.exoplatform.com 7 Copyright 2011 eXo Platform
  8. 8. IOC: Pros and Cons» Pros: – Loosely Coupled – Increases Tesability – Separates component clearly. – Allows for use of Inversion of Control Container.» Cons: – Increases code complexity – Difficult to understand at First – Complicate Debugging at First – Complicates following Code Flow. www.exoplatform.com 8 Copyright 2011 eXo Platform
  9. 9. Time for Injector - BoorStrapping the Injector» Constructed and prepared before it can be used. – In the init lifecycle stage of a web application. – On startup of a desktop program www.exoplatform.com 9 Copyright 2011 eXo Platform
  10. 10. IOC - Metadata and Injector Configuration» XML configuration file.» Annotations(@Injector, @Singleton, …)» Invoking into a programmatic API. www.exoplatform.com 10 Copyright 2011 eXo Platform
  11. 11. Boorstrapping the Injector(Cont)» Constructed and prepared before it can be used. – On demand, every time it is needed – Lazily, when it is first needed www.exoplatform.com 11 Copyright 2011 eXo Platform
  12. 12. IOC - What is Scope?Fixed duration of time or method calls in which an object exist. General-purpose scopes: Singleton and No-scope.» Web Application: – Request, Session and Conversation scope – Transaction scope www.exoplatform.com 12 Copyright 2011 eXo Platform
  13. 13. IOC - Benefit of Scope» Lets injector manage the latent state of your objects» Ensures that your services get new instances of dependencies as needed» Implicitly separates state by context. www.exoplatform.com 13 Copyright 2011 eXo Platform
  14. 14. DEMO www.exoplatform.com Copyright 2011 eXo Platform
  15. 15. Wha t? www.exoplatform.com Copyright 2011 eXo Platform
  16. 16. What? www.exoplatform.com 16 Copyright 2011 eXo Platform
  17. 17. What?AOP - Enables encapsulation of functionality that affects multipleclasses in separate units - Complements object oriented programming - Is not about “patching” pieces of code. About performing anaction systematically upon recognition of a behavior in the code. www.exoplatform.com 17 Copyright 2011 eXo Platform
  18. 18. Why? Benefits: - Separates persistence and specific functionality (logging, security...) - Promotes code reuse and modularization - Decouples codes (the LogFactory from the DAO impl’s) www.exoplatform.com 18 Copyright 2011 eXo Platform
  19. 19. AOP vs OOP Object Oriented Aspect Oriented Class – code unit that Aspect – code unit that encapsulates methods and encapsulates pointcuts, advice, attributes. and attributes. Method signatures – define Pointcut – define the set of the entry points for the entry points (triggers) in which execution of method bodies. advice is executed. Method bodies – Advice – implementations of the implementations of the cross cutting concerns. primary concerns. Compiler – converts source Weaver – instruments code code into object code. (source or object) with advice. www.exoplatform.com 19 Copyright 2011 eXo Platform
  20. 20. Concepts- Crosscutting Concerns- Aspect: The merger of advice and pointcuts. All information about where, when and what job is to be done.- Advice: The job of an aspect. Defines the what and when of an aspect.- Pointcut: Pointcuts help narrow down the joinpoints advised by an aspect. Define the where of an aspect.- Joinpoint: A point in the execution of an application where an aspect can be plugged in. All the opportunities for advice to be applied. www.exoplatform.com 20 Copyright 2011 eXo Platform
  21. 21. Concepts- Target: Object being advised.- Proxy: The object created after applying advice to the target object. To the clientmaking use of the target object the proxy looks the same.- Weaving: Process of applying aspects to a target object to create a new, proxiedobject. www.exoplatform.com 21 Copyright 2011 eXo Platform
  22. 22. How it works? www.exoplatform.com 22 Copyright 2011 eXo Platform
  23. 23. www.exoplatform.com23 Copyright 2011 eXo Platform
  24. 24. Th a n k yo u ! www.exoplatform.com Copyright 2011 eXo Platform

×