0
Introduction to    Aspect Oriented Programmingby Yan Cui   @theburningmonk             theburningmonk.com
Server-side Developer @
• Overview  Cross-Cutting Concerns  AOP  What’s in it for you• AOP  Terminologies  AOP and OOP  Solutions• Q&A
the PROBLEM...CROSS-CUTTING CONCERNS
Cross-Cutting Concerns                  Image by Mike Rohde
• Cuts across multiple abstractions• Difficult to decompose• High-coupling• Boilerplate code
• Code tangling and scattering  Poor traceability  Lower productivity  Less code reuse  Harder refactoring
the SOLUTION...ASPECT-ORIENTED PROGRAMMING
“AOP is a programming paradigm whichaims to increase modularity by allowingthe separation of cross-cutting concerns”  - wi...
AOP      Image by Mike Rohde
• Centralize concerns implementation• Intercept method calls• Inject new behaviour• More reusable code• Cleaner code
What’s in it for YOU?
• Write less code• Read less code• More concise and easy to understand• More maintainable
• Fewer code = FEWER DEFECTS!• Less boilerplate code• More interesting work• Increased attention• More PRODUCTIVITY!
dive a little deeper into...AOP
• Join Point  Place where behaviour can be added  start/end of method  property getter/setter  ...
• Advice  Code that’s injected at join points  Logging  Validation  ...
• Point cut  Join points where advice should be   applied
• Aspect  Container holding point cuts and advice  Aspect is to AOP what class is to OOP
• Weaving  Combines advices with point cuts
• AOP is complementary to OOP• AOP targets a specific problem• Code modularization  OOP – Real world objects  AOP – Func...
• Help you S.O.L.I.Dify your code  Single responsibility  Open/close
• You can do AOP via:  Dynamic Proxies  Functional Programming  Code Generation  Dynamic Languages  Static Weaving
AOP via...DYNAMIC PROXIES
• IoC framesworks  Castle  Spring.Net• Dynamic interceptors
Dynamic Proxies            Image by Mike Rohde
• Advantages  Can use existing DI framework  Built-in aspects (logging, etc.)  Aspects can be configured after build
• Disadvantages  Significant change to base code required to adapt  Limited AOP features  Do not work on static, non-pu...
NOOOO Sir!!Class, is AOP the same as Dependency Injection?
AOP via...FUNCTIONAL PROGRAMMING
Functional Programming             Image by Mike Rohde
• Advantages  No external dependencies
• Disadvantages  Requires modification to every function  No support for matching rules  Manual aspect composition
AOP via...CODE GENERATION
• T4, CodeSmith tools
• Advantages  Easy to generate complex source code
• Disadvantages  Input is usually XML  Cannot inject new behaviour to existing  code
AOP via...DYNAMIC LANGUAGES
Dynamic Languages              Image by Mike Rohde
• Advantages  Meta-programming is easy
• Disadvantages  Switch to a dynamic language can be hard  No (limited) Visual Studio tooling
AOP via...STATIC WEAVING
• PostSharp, AspectJ• Uses low-level MSIL transformation• Compile time
Requirements          Aspect DecompositionAspects                          Core program          Aspect Recomposition     ...
PostSharp            Image by Mike Rohde
• Advantages  Most complete support of AOP features  Aspect usage is verified at build time  Better runtime performance
• Disadvantages  Increased build time  New to many developers
PostSharp Examples• Auto-implement INotifyPropertyChanged• Undo/Redo• Thread dispatching• Transaction handling• Performanc...
• Performance Monitoring  Method execution time  Method execution count  Error count
Record exec time           Publish to Amazon CloudWatch
• Amazon CloudWatch  Cheap to run  Supports alarms and notifications  Visualization tool
• http://bit.ly/KRDdgr
Thank You!  @theburningmonktheburningmonk.com
Introduction to Aspect Oriented Programming (DDD South West 4.0)
Introduction to Aspect Oriented Programming (DDD South West 4.0)
Introduction to Aspect Oriented Programming (DDD South West 4.0)
Introduction to Aspect Oriented Programming (DDD South West 4.0)
Introduction to Aspect Oriented Programming (DDD South West 4.0)
Introduction to Aspect Oriented Programming (DDD South West 4.0)
Upcoming SlideShare
Loading in...5
×

Introduction to Aspect Oriented Programming (DDD South West 4.0)

5,355

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
0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
5,355
On Slideshare
0
From Embeds
0
Number of Embeds
2
Actions
Shares
0
Downloads
35
Comments
0
Likes
1
Embeds 0
No embeds

No notes for slide

Transcript of "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
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×