1 / 59

Introduction to

Introduction to. Aspect Oriented Programming. Yan Cui. by. @theburningmonk. theburningmonk.com. Server-side Developer @. 600K+ DAU. 150M reqs/day. 15K IO op/s. 200+ servers. 40K+ concurrent users. 2500 reqs/s. 75ms avg latency. Overview Cross-Cutting Concerns AOP

adonai
Download Presentation

Introduction to

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Introduction to Aspect Oriented Programming Yan Cui by @theburningmonk theburningmonk.com

  2. Server-side Developer @

  3. 600K+ DAU 150M reqs/day 15K IO op/s 200+ servers 40K+ concurrent users 2500 reqs/s 75ms avg latency

  4. Overview • Cross-Cutting Concerns • AOP • What’s in it for you • AOP • Terminologies • AOP and OOP • Solutions • Q&A

  5. the PROBLEM... Cross-cutting concerns

  6. Cross-Cutting Concerns

  7. Cuts across multiple abstractions • Difficult to decompose • High-coupling • Boilerplate code

  8. Code tangling and scattering • Poor traceability • Lower productivity • Less code reuse • Harder refactoring

  9. the SOLUTION... Aspect-Oriented Programming

  10. “AOP is a programming paradigm which aims to increase modularity by allowing the separation of cross-cutting concerns” - wikipedia

  11. AOP AOP AOP AOP AOP AOP AOP

  12. AOP

  13. Centralize concerns implementation • Intercept method calls • Inject new behaviour • More reusable code • Cleaner code

  14. What’s in it for YOU?

  15. Write less code • Read less code • More concise and easy to understand • More maintainable

  16. Fewer code = • Less boilerplate code • More interesting work • Increased attention • More PRODUCTIVITY! FEWER DEFECTS!

  17. dive a little deeper into... AOP

  18. Join Point • Place where behaviour can be added • start/end of method • property getter/setter • ...

  19. Advice • Code that’s injected at join points • Logging • Validation • ...

  20. Point cut • Join points where advice should be applied

  21. Aspect • Container holding point cuts and advice • Aspect is to AOP what class is to OOP

  22. Weaving • Combines advices with point cuts

  23. AOP is complementary to OOP • AOP targets a specific problem • Code modularization • OOP – Real world objects • AOP – Functionalities

  24. Help you S.O.L.I.Dify your code • Single responsibility • Open/close

  25. You can do AOP via: • Dynamic Proxies • Functional Programming • Code Generation • Dynamic Languages • Static Weaving

  26. AOP via... Dynamic Proxies

  27. IoCframesworks • Castle • Spring.Net • Dynamic interceptors

  28. Dynamic Proxies

  29. Advantages • Can use existing DI framework • Built-in aspects (logging, etc.) • Aspects can be configured after build

  30. 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

  31. NOOOO Sir!! Class, is AOP the same as Dependency Injection?

  32. AOP via... Functional Programming

  33. Functional Programming

  34. Advantages • No external dependencies

  35. Disadvantages • Requires modification to every function • No support for matching rules • Manual aspect composition

  36. AOP via... Code generation

  37. T4, CodeSmith tools

  38. Advantages • Easy to generate complex source code

  39. Disadvantages • Input is usually XML • Cannot inject new behaviour to existing code

  40. AOP via... Dynamic Languages

  41. Dynamic Languages

  42. Advantages • Meta-programming is easy

  43. Disadvantages • Switch to a dynamic language can be hard • No (limited) Visual Studio tooling

  44. AOP via... Static weaving

  45. PostSharp, AspectJ • Uses low-level MSIL transformation • Compile time

  46. Requirements Aspect Decomposition Aspects Core program Aspect Recomposition Final System

  47. PostSharp

More Related