Download presentation
Presentation is loading. Please wait.
Published byDarlene Grant Modified over 9 years ago
1
Introduction to Yan Cui Aspect Oriented Programming by theburningmonk.com @theburningmonk
2
Server-side Developer @
4
Overview Cross-Cutting Concerns AOP What’s in it for you AOP Terminologies AOP and OOP Solutions Q&A
5
C ROSS -C UTTING C ONCERNS the PROBLEM...
6
Image by Mike Rohde 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
A SPECT -O RIENTED P ROGRAMMING the SOLUTION...
10
“AOP is a programming paradigm which aims to increase modularity by allowing the separation of cross-cutting concerns” - wikipedia
11
AOP
12
Image by Mike Rohde 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
AOP dive a little deeper into...
19
Join Point Place where behaviour can be added start/end of method property getter/setter ...
20
Advice Code that’s injected at join points Logging Validation ...
21
Point cut Join points where advice should be applied
22
Aspect Container holding point cuts and advice Aspect is to AOP what class is to OOP
23
Weaving Combines advices with point cuts
24
AOP is complementary to OOP AOP targets a specific problem Code modularization OOP – Real world objects AOP – Functionalities
25
Help you S.O.L.I.Dify your code Single responsibility Open/close
26
You can do AOP via: Dynamic Proxies Functional Programming Code Generation Dynamic Languages Static Weaving
27
D YNAMIC P ROXIES AOP via...
28
IoC framesworks Castle Spring.Net Dynamic interceptors
29
Image by Mike Rohde Dynamic Proxies
31
Advantages Can use existing DI framework Built-in aspects (logging, etc.) Aspects can be configured after build
32
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
33
Class, is AOP the same as Dependency Injection? NOOOO Sir!!
34
F UNCTIONAL P ROGRAMMING AOP via...
35
Image by Mike Rohde Functional Programming
37
Advantages No external dependencies
38
Disadvantages Requires modification to every function No support for matching rules Manual aspect composition
39
C ODE G ENERATION AOP via...
40
T4, CodeSmith tools
41
Advantages Easy to generate complex source code
42
Disadvantages Input is usually XML Cannot inject new behaviour to existing code
43
D YNAMIC L ANGUAGES AOP via...
44
Image by Mike Rohde Dynamic Languages
45
Advantages Meta-programming is easy
46
Disadvantages Switch to a dynamic language can be hard No (limited) Visual Studio tooling
47
S TATIC W EAVING AOP via...
48
PostSharp, AspectJ Uses low-level MSIL transformation Compile time
49
Aspect Decomposition Aspects Core program Aspect Recomposition Requirements Final System
50
Image by Mike Rohde PostSharp
51
Advantages Most complete support of AOP features Aspect usage is verified at build time Better runtime performance
52
Disadvantages Increased build time New to many developers
53
PostSharp Examples Auto-implement INotifyPropertyChanged Undo/Redo Thread dispatching Transaction handling Performance Monitoring
54
Method execution time Method execution count Error count
55
Record exec time Publish to Amazon CloudWatch
57
Amazon CloudWatch Cheap to run Supports alarms and notifications Visualization tool
58
http://bit.ly/KRDdgr
59
Thank You! @theburningmonk theburningmonk.com @theburningmonk theburningmonk.com
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.