1 / 53

Aspect-oriented programming

Yan Cui. Aspect-oriented programming. Server-side Developer @. “Our mission is to build fun games and game apps that people can play, anywhere, anytime.”. 400k DAU 100m requests/day. Overview Cross-Cutting Concerns AOP What’s in it for you AOP Terminologies AOP and OOP Solutions Q&A.

iram
Download Presentation

Aspect-oriented programming

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. Yan Cui Aspect-oriented programming

  2. Server-side Developer @ “Our mission is to build fun games and game apps that people can play, anywhere, anytime.” 400k DAU 100m requests/day

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

  4. The PROBLEM… Cross-Cutting Concerns

  5. Cross-Cutting Concerns Image by Mike Rohde

  6. Function Requirements Non-Functional Requirements Production Code + =

  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. Coding is HARD AOP makes it EASY

  12. AOP AOP AOP AOP AOP AOP AOP

  13. AOP

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

  15. What’s in it for YOU?

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

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

  18. Diving a little deeper… AOP

  19. Join Point • Place where behaviour can be added • Advice • Code that can be injected at join points • Point cut • Join points where advice should be applied • Aspect • Container holding point cuts and advice • Weaving • Combines advices with point cuts

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

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

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

  23. AOP via... Dynamic Proxies

  24. IoCframesworks (Castle, Spring.Net) • Dynamic interceptors

  25. Dynamic Proxies

  26. Advantages • Can use existing DI framework • Some frameworks provides built-in aspects • Aspects can be configured after build

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

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

  29. AOP via... Functional Programming

  30. Functional Programming

  31. Advantages • No external dependencies

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

  33. AOP via… Code Generation

  34. T4, CodeSmith Tools

  35. Advantages • Easy to generate complex source code

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

  37. AOP via… Dynamic Languages

  38. Dynamic Languages

  39. Advantages • Meta-programming is easy

  40. Disadvantages • Switching to a dynamic language can be scary • No (limited) Visual Studio tooling

  41. AOP via… Static Weaving

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

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

  44. Aspectual Decomposition • Identify primary and cross-cutting concerns • Concern Implementation • Implement concerns separately • Primary concern as Core Component using OO • Cross-cutting concerns as aspect • Aspectual Recomposition • Aspect weaver to weave the separately implemented code into a final system

  45. PostSharp

  46. Advantages • Most complete support of AOP features • Aspect usage is verified at build time • Better runtime performance

  47. Disadvantages • Increased build time • New to many developers

More Related