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.

Introduction to Aspect Oriented Programming (DDD South West 4.0)

6,534 views

Published on

Introduction to AOP talk at DDD SouthWest 4.0, including examples of AOP using dynamic proxies, functional programming, dynamic language and PostSharp.

Published in: Technology
  • Be the first to comment

Introduction to Aspect Oriented Programming (DDD South West 4.0)

  1. 1. Introduction to Aspect Oriented Programmingby Yan Cui @theburningmonk theburningmonk.com
  2. 2. Server-side Developer @
  3. 3. • Overview  Cross-Cutting Concerns  AOP  What’s in it for you• AOP  Terminologies  AOP and OOP  Solutions• Q&A
  4. 4. the PROBLEM...CROSS-CUTTING CONCERNS
  5. 5. Cross-Cutting Concerns Image by Mike Rohde
  6. 6. • Cuts across multiple abstractions• Difficult to decompose• High-coupling• Boilerplate code
  7. 7. • Code tangling and scattering  Poor traceability  Lower productivity  Less code reuse  Harder refactoring
  8. 8. the SOLUTION...ASPECT-ORIENTED PROGRAMMING
  9. 9. “AOP is a programming paradigm whichaims to increase modularity by allowingthe separation of cross-cutting concerns” - wikipedia
  10. 10. AOP Image by Mike Rohde
  11. 11. • Centralize concerns implementation• Intercept method calls• Inject new behaviour• More reusable code• Cleaner code
  12. 12. What’s in it for YOU?
  13. 13. • Write less code• Read less code• More concise and easy to understand• More maintainable
  14. 14. • Fewer code = FEWER DEFECTS!• Less boilerplate code• More interesting work• Increased attention• More PRODUCTIVITY!
  15. 15. dive a little deeper into...AOP
  16. 16. • Join Point  Place where behaviour can be added  start/end of method  property getter/setter  ...
  17. 17. • Advice  Code that’s injected at join points  Logging  Validation  ...
  18. 18. • Point cut  Join points where advice should be applied
  19. 19. • Aspect  Container holding point cuts and advice  Aspect is to AOP what class is to OOP
  20. 20. • Weaving  Combines advices with point cuts
  21. 21. • AOP is complementary to OOP• AOP targets a specific problem• Code modularization  OOP – Real world objects  AOP – Functionalities
  22. 22. • Help you S.O.L.I.Dify your code  Single responsibility  Open/close
  23. 23. • You can do AOP via:  Dynamic Proxies  Functional Programming  Code Generation  Dynamic Languages  Static Weaving
  24. 24. AOP via...DYNAMIC PROXIES
  25. 25. • IoC framesworks  Castle  Spring.Net• Dynamic interceptors
  26. 26. Dynamic Proxies Image by Mike Rohde
  27. 27. • Advantages  Can use existing DI framework  Built-in aspects (logging, etc.)  Aspects can be configured after build
  28. 28. • Disadvantages  Significant change to base code required to adapt  Limited AOP features  Do not work on static, non-public methods  Do not work on fields, properties, or events  Higher run-time overhead  No build-time verification  Objects must be instantiated using the container
  29. 29. NOOOO Sir!!Class, is AOP the same as Dependency Injection?
  30. 30. AOP via...FUNCTIONAL PROGRAMMING
  31. 31. Functional Programming Image by Mike Rohde
  32. 32. • Advantages  No external dependencies
  33. 33. • Disadvantages  Requires modification to every function  No support for matching rules  Manual aspect composition
  34. 34. AOP via...CODE GENERATION
  35. 35. • T4, CodeSmith tools
  36. 36. • Advantages  Easy to generate complex source code
  37. 37. • Disadvantages  Input is usually XML  Cannot inject new behaviour to existing code
  38. 38. AOP via...DYNAMIC LANGUAGES
  39. 39. Dynamic Languages Image by Mike Rohde
  40. 40. • Advantages  Meta-programming is easy
  41. 41. • Disadvantages  Switch to a dynamic language can be hard  No (limited) Visual Studio tooling
  42. 42. AOP via...STATIC WEAVING
  43. 43. • PostSharp, AspectJ• Uses low-level MSIL transformation• Compile time
  44. 44. Requirements Aspect DecompositionAspects Core program Aspect Recomposition Final System
  45. 45. PostSharp Image by Mike Rohde
  46. 46. • Advantages  Most complete support of AOP features  Aspect usage is verified at build time  Better runtime performance
  47. 47. • Disadvantages  Increased build time  New to many developers
  48. 48. PostSharp Examples• Auto-implement INotifyPropertyChanged• Undo/Redo• Thread dispatching• Transaction handling• Performance Monitoring
  49. 49. • Performance Monitoring  Method execution time  Method execution count  Error count
  50. 50. Record exec time Publish to Amazon CloudWatch
  51. 51. • Amazon CloudWatch  Cheap to run  Supports alarms and notifications  Visualization tool
  52. 52. • http://bit.ly/KRDdgr
  53. 53. Thank You! @theburningmonktheburningmonk.com

×