introduction to aspect oriented programming (ddd south west 4.0)
DESCRIPTION
Introduction to AOP talk at DDD SouthWest 4.0, including examples of AOP using dynamic proxies, functional programming, dynamic language and PostSharp.TRANSCRIPT
![Page 1: Introduction to Aspect Oriented Programming (DDD South West 4.0)](https://reader036.vdocuments.us/reader036/viewer/2022081508/5587c280d8b42a2c208b45ad/html5/thumbnails/1.jpg)
Introduction to
Yan Cui
Aspect Oriented Programming
bytheburningmonk.com@theburningmonk
![Page 2: Introduction to Aspect Oriented Programming (DDD South West 4.0)](https://reader036.vdocuments.us/reader036/viewer/2022081508/5587c280d8b42a2c208b45ad/html5/thumbnails/2.jpg)
Server-side Developer @
![Page 3: Introduction to Aspect Oriented Programming (DDD South West 4.0)](https://reader036.vdocuments.us/reader036/viewer/2022081508/5587c280d8b42a2c208b45ad/html5/thumbnails/3.jpg)
600K+ DAU150M reqs/day
2500 reqs/s
15K IO op/s 200+ servers
75ms avg latency
40K+ concurrent users
![Page 4: Introduction to Aspect Oriented Programming (DDD South West 4.0)](https://reader036.vdocuments.us/reader036/viewer/2022081508/5587c280d8b42a2c208b45ad/html5/thumbnails/4.jpg)
• Overview Cross-Cutting Concerns AOP What’s in it for you
• AOP Terminologies AOP and OOP Solutions
• Q&A
![Page 5: Introduction to Aspect Oriented Programming (DDD South West 4.0)](https://reader036.vdocuments.us/reader036/viewer/2022081508/5587c280d8b42a2c208b45ad/html5/thumbnails/5.jpg)
CROSS-CUTTING CONCERNS
the PROBLEM...
![Page 6: Introduction to Aspect Oriented Programming (DDD South West 4.0)](https://reader036.vdocuments.us/reader036/viewer/2022081508/5587c280d8b42a2c208b45ad/html5/thumbnails/6.jpg)
Image by Mike Rohde
Cross-Cutting
Concerns
![Page 7: Introduction to Aspect Oriented Programming (DDD South West 4.0)](https://reader036.vdocuments.us/reader036/viewer/2022081508/5587c280d8b42a2c208b45ad/html5/thumbnails/7.jpg)
• Cuts across multiple abstractions
• Difficult to decompose
• High-coupling
• Boilerplate code
![Page 8: Introduction to Aspect Oriented Programming (DDD South West 4.0)](https://reader036.vdocuments.us/reader036/viewer/2022081508/5587c280d8b42a2c208b45ad/html5/thumbnails/8.jpg)
• Code tangling and scattering Poor traceability
Lower productivity
Less code reuse
Harder refactoring
![Page 9: Introduction to Aspect Oriented Programming (DDD South West 4.0)](https://reader036.vdocuments.us/reader036/viewer/2022081508/5587c280d8b42a2c208b45ad/html5/thumbnails/9.jpg)
ASPECT-ORIENTED PROGRAMMING
the SOLUTION...
![Page 10: Introduction to Aspect Oriented Programming (DDD South West 4.0)](https://reader036.vdocuments.us/reader036/viewer/2022081508/5587c280d8b42a2c208b45ad/html5/thumbnails/10.jpg)
“AOP is a programming paradigm which aims to increase modularity by allowing the separation of cross-cutting concerns”
- wikipedia
![Page 11: Introduction to Aspect Oriented Programming (DDD South West 4.0)](https://reader036.vdocuments.us/reader036/viewer/2022081508/5587c280d8b42a2c208b45ad/html5/thumbnails/11.jpg)
AO
P
AOP
AO
PA
OP
AO
P
AO
P
AO
P
![Page 12: Introduction to Aspect Oriented Programming (DDD South West 4.0)](https://reader036.vdocuments.us/reader036/viewer/2022081508/5587c280d8b42a2c208b45ad/html5/thumbnails/12.jpg)
Image by Mike Rohde
AOP
![Page 13: Introduction to Aspect Oriented Programming (DDD South West 4.0)](https://reader036.vdocuments.us/reader036/viewer/2022081508/5587c280d8b42a2c208b45ad/html5/thumbnails/13.jpg)
![Page 14: Introduction to Aspect Oriented Programming (DDD South West 4.0)](https://reader036.vdocuments.us/reader036/viewer/2022081508/5587c280d8b42a2c208b45ad/html5/thumbnails/14.jpg)
• Centralize concerns implementation
• Intercept method calls
• Inject new behaviour
• More reusable code
• Cleaner code
![Page 15: Introduction to Aspect Oriented Programming (DDD South West 4.0)](https://reader036.vdocuments.us/reader036/viewer/2022081508/5587c280d8b42a2c208b45ad/html5/thumbnails/15.jpg)
What’s in it for YOU?
![Page 16: Introduction to Aspect Oriented Programming (DDD South West 4.0)](https://reader036.vdocuments.us/reader036/viewer/2022081508/5587c280d8b42a2c208b45ad/html5/thumbnails/16.jpg)
• Write less code
• Read less code
• More concise and easy to understand
• More maintainable
![Page 17: Introduction to Aspect Oriented Programming (DDD South West 4.0)](https://reader036.vdocuments.us/reader036/viewer/2022081508/5587c280d8b42a2c208b45ad/html5/thumbnails/17.jpg)
• Fewer code =
• Less boilerplate code
• More interesting work
• Increased attention
• More PRODUCTIVITY!
FEWER DEFECTS!
![Page 18: Introduction to Aspect Oriented Programming (DDD South West 4.0)](https://reader036.vdocuments.us/reader036/viewer/2022081508/5587c280d8b42a2c208b45ad/html5/thumbnails/18.jpg)
AOPdive a little deeper into...
![Page 19: Introduction to Aspect Oriented Programming (DDD South West 4.0)](https://reader036.vdocuments.us/reader036/viewer/2022081508/5587c280d8b42a2c208b45ad/html5/thumbnails/19.jpg)
• Join Point Place where behaviour can be added
start/end of method
property getter/setter
...
![Page 20: Introduction to Aspect Oriented Programming (DDD South West 4.0)](https://reader036.vdocuments.us/reader036/viewer/2022081508/5587c280d8b42a2c208b45ad/html5/thumbnails/20.jpg)
• Advice Code that’s injected at join points
Logging
Validation
...
![Page 21: Introduction to Aspect Oriented Programming (DDD South West 4.0)](https://reader036.vdocuments.us/reader036/viewer/2022081508/5587c280d8b42a2c208b45ad/html5/thumbnails/21.jpg)
• Point cut Join points where advice should be
applied
![Page 22: Introduction to Aspect Oriented Programming (DDD South West 4.0)](https://reader036.vdocuments.us/reader036/viewer/2022081508/5587c280d8b42a2c208b45ad/html5/thumbnails/22.jpg)
• Aspect Container holding point cuts and advice
Aspect is to AOP what class is to OOP
![Page 23: Introduction to Aspect Oriented Programming (DDD South West 4.0)](https://reader036.vdocuments.us/reader036/viewer/2022081508/5587c280d8b42a2c208b45ad/html5/thumbnails/23.jpg)
• Weaving Combines advices with point cuts
![Page 24: Introduction to Aspect Oriented Programming (DDD South West 4.0)](https://reader036.vdocuments.us/reader036/viewer/2022081508/5587c280d8b42a2c208b45ad/html5/thumbnails/24.jpg)
• AOP is complementary to OOP
• AOP targets a specific problem
• Code modularization OOP – Real world objects
AOP – Functionalities
![Page 25: Introduction to Aspect Oriented Programming (DDD South West 4.0)](https://reader036.vdocuments.us/reader036/viewer/2022081508/5587c280d8b42a2c208b45ad/html5/thumbnails/25.jpg)
• Help you S.O.L.I.Dify your code Single responsibility
Open/close
![Page 26: Introduction to Aspect Oriented Programming (DDD South West 4.0)](https://reader036.vdocuments.us/reader036/viewer/2022081508/5587c280d8b42a2c208b45ad/html5/thumbnails/26.jpg)
• You can do AOP via: Dynamic Proxies
Functional Programming
Code Generation
Dynamic Languages
Static Weaving
![Page 27: Introduction to Aspect Oriented Programming (DDD South West 4.0)](https://reader036.vdocuments.us/reader036/viewer/2022081508/5587c280d8b42a2c208b45ad/html5/thumbnails/27.jpg)
DYNAMIC PROXIES
AOP via...
![Page 28: Introduction to Aspect Oriented Programming (DDD South West 4.0)](https://reader036.vdocuments.us/reader036/viewer/2022081508/5587c280d8b42a2c208b45ad/html5/thumbnails/28.jpg)
• IoC framesworks Castle
Spring.Net
• Dynamic interceptors
![Page 29: Introduction to Aspect Oriented Programming (DDD South West 4.0)](https://reader036.vdocuments.us/reader036/viewer/2022081508/5587c280d8b42a2c208b45ad/html5/thumbnails/29.jpg)
Image by Mike Rohde
Dynamic Proxies
![Page 30: Introduction to Aspect Oriented Programming (DDD South West 4.0)](https://reader036.vdocuments.us/reader036/viewer/2022081508/5587c280d8b42a2c208b45ad/html5/thumbnails/30.jpg)
![Page 31: Introduction to Aspect Oriented Programming (DDD South West 4.0)](https://reader036.vdocuments.us/reader036/viewer/2022081508/5587c280d8b42a2c208b45ad/html5/thumbnails/31.jpg)
• Advantages Can use existing DI framework
Built-in aspects (logging, etc.)
Aspects can be configured after build
![Page 32: Introduction to Aspect Oriented Programming (DDD South West 4.0)](https://reader036.vdocuments.us/reader036/viewer/2022081508/5587c280d8b42a2c208b45ad/html5/thumbnails/32.jpg)
• 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
![Page 33: Introduction to Aspect Oriented Programming (DDD South West 4.0)](https://reader036.vdocuments.us/reader036/viewer/2022081508/5587c280d8b42a2c208b45ad/html5/thumbnails/33.jpg)
Class, is AOP the same as Dependency Injection?
NOOOO Sir!!
![Page 34: Introduction to Aspect Oriented Programming (DDD South West 4.0)](https://reader036.vdocuments.us/reader036/viewer/2022081508/5587c280d8b42a2c208b45ad/html5/thumbnails/34.jpg)
FUNCTIONAL PROGRAMMING
AOP via...
![Page 35: Introduction to Aspect Oriented Programming (DDD South West 4.0)](https://reader036.vdocuments.us/reader036/viewer/2022081508/5587c280d8b42a2c208b45ad/html5/thumbnails/35.jpg)
Image by Mike Rohde
Functional
Programming
![Page 36: Introduction to Aspect Oriented Programming (DDD South West 4.0)](https://reader036.vdocuments.us/reader036/viewer/2022081508/5587c280d8b42a2c208b45ad/html5/thumbnails/36.jpg)
![Page 37: Introduction to Aspect Oriented Programming (DDD South West 4.0)](https://reader036.vdocuments.us/reader036/viewer/2022081508/5587c280d8b42a2c208b45ad/html5/thumbnails/37.jpg)
• Advantages No external dependencies
![Page 38: Introduction to Aspect Oriented Programming (DDD South West 4.0)](https://reader036.vdocuments.us/reader036/viewer/2022081508/5587c280d8b42a2c208b45ad/html5/thumbnails/38.jpg)
• Disadvantages Requires modification to every function
No support for matching rules
Manual aspect composition
![Page 39: Introduction to Aspect Oriented Programming (DDD South West 4.0)](https://reader036.vdocuments.us/reader036/viewer/2022081508/5587c280d8b42a2c208b45ad/html5/thumbnails/39.jpg)
CODE GENERATION
AOP via...
![Page 40: Introduction to Aspect Oriented Programming (DDD South West 4.0)](https://reader036.vdocuments.us/reader036/viewer/2022081508/5587c280d8b42a2c208b45ad/html5/thumbnails/40.jpg)
• T4, CodeSmith tools
![Page 41: Introduction to Aspect Oriented Programming (DDD South West 4.0)](https://reader036.vdocuments.us/reader036/viewer/2022081508/5587c280d8b42a2c208b45ad/html5/thumbnails/41.jpg)
• Advantages Easy to generate complex source code
![Page 42: Introduction to Aspect Oriented Programming (DDD South West 4.0)](https://reader036.vdocuments.us/reader036/viewer/2022081508/5587c280d8b42a2c208b45ad/html5/thumbnails/42.jpg)
• Disadvantages Input is usually XML
Cannot inject new behaviour to existing
code
![Page 43: Introduction to Aspect Oriented Programming (DDD South West 4.0)](https://reader036.vdocuments.us/reader036/viewer/2022081508/5587c280d8b42a2c208b45ad/html5/thumbnails/43.jpg)
DYNAMIC LANGUAGES
AOP via...
![Page 44: Introduction to Aspect Oriented Programming (DDD South West 4.0)](https://reader036.vdocuments.us/reader036/viewer/2022081508/5587c280d8b42a2c208b45ad/html5/thumbnails/44.jpg)
Image by Mike Rohde
Dynamic
Languages
![Page 45: Introduction to Aspect Oriented Programming (DDD South West 4.0)](https://reader036.vdocuments.us/reader036/viewer/2022081508/5587c280d8b42a2c208b45ad/html5/thumbnails/45.jpg)
• Advantages Meta-programming is easy
![Page 46: Introduction to Aspect Oriented Programming (DDD South West 4.0)](https://reader036.vdocuments.us/reader036/viewer/2022081508/5587c280d8b42a2c208b45ad/html5/thumbnails/46.jpg)
• Disadvantages Switch to a dynamic language can be hard
No (limited) Visual Studio tooling
![Page 47: Introduction to Aspect Oriented Programming (DDD South West 4.0)](https://reader036.vdocuments.us/reader036/viewer/2022081508/5587c280d8b42a2c208b45ad/html5/thumbnails/47.jpg)
STATIC WEAVING
AOP via...
![Page 48: Introduction to Aspect Oriented Programming (DDD South West 4.0)](https://reader036.vdocuments.us/reader036/viewer/2022081508/5587c280d8b42a2c208b45ad/html5/thumbnails/48.jpg)
• PostSharp, AspectJ
• Uses low-level MSIL transformation
• Compile time
![Page 49: Introduction to Aspect Oriented Programming (DDD South West 4.0)](https://reader036.vdocuments.us/reader036/viewer/2022081508/5587c280d8b42a2c208b45ad/html5/thumbnails/49.jpg)
Aspect Decomposition
Aspects Core program
Aspect Recomposition
Requirements
Final System
![Page 50: Introduction to Aspect Oriented Programming (DDD South West 4.0)](https://reader036.vdocuments.us/reader036/viewer/2022081508/5587c280d8b42a2c208b45ad/html5/thumbnails/50.jpg)
Image by Mike Rohde
PostSharp
![Page 51: Introduction to Aspect Oriented Programming (DDD South West 4.0)](https://reader036.vdocuments.us/reader036/viewer/2022081508/5587c280d8b42a2c208b45ad/html5/thumbnails/51.jpg)
• Advantages Most complete support of AOP features
Aspect usage is verified at build time
Better runtime performance
![Page 52: Introduction to Aspect Oriented Programming (DDD South West 4.0)](https://reader036.vdocuments.us/reader036/viewer/2022081508/5587c280d8b42a2c208b45ad/html5/thumbnails/52.jpg)
• Disadvantages Increased build time
New to many developers
![Page 53: Introduction to Aspect Oriented Programming (DDD South West 4.0)](https://reader036.vdocuments.us/reader036/viewer/2022081508/5587c280d8b42a2c208b45ad/html5/thumbnails/53.jpg)
PostSharp Examples• Auto-implement INotifyPropertyChanged
• Undo/Redo
• Thread dispatching
• Transaction handling
• Performance Monitoring
![Page 54: Introduction to Aspect Oriented Programming (DDD South West 4.0)](https://reader036.vdocuments.us/reader036/viewer/2022081508/5587c280d8b42a2c208b45ad/html5/thumbnails/54.jpg)
• Performance Monitoring Method execution time
Method execution count
Error count
![Page 55: Introduction to Aspect Oriented Programming (DDD South West 4.0)](https://reader036.vdocuments.us/reader036/viewer/2022081508/5587c280d8b42a2c208b45ad/html5/thumbnails/55.jpg)
Record exec time
Publish to Amazon CloudWatch
![Page 56: Introduction to Aspect Oriented Programming (DDD South West 4.0)](https://reader036.vdocuments.us/reader036/viewer/2022081508/5587c280d8b42a2c208b45ad/html5/thumbnails/56.jpg)
![Page 57: Introduction to Aspect Oriented Programming (DDD South West 4.0)](https://reader036.vdocuments.us/reader036/viewer/2022081508/5587c280d8b42a2c208b45ad/html5/thumbnails/57.jpg)
• Amazon CloudWatch Cheap to run
Supports alarms and notifications
Visualization tool
![Page 58: Introduction to Aspect Oriented Programming (DDD South West 4.0)](https://reader036.vdocuments.us/reader036/viewer/2022081508/5587c280d8b42a2c208b45ad/html5/thumbnails/58.jpg)
• http://bit.ly/KRDdgr
![Page 59: Introduction to Aspect Oriented Programming (DDD South West 4.0)](https://reader036.vdocuments.us/reader036/viewer/2022081508/5587c280d8b42a2c208b45ad/html5/thumbnails/59.jpg)
Thank You!
@theburningmonktheburningmonk.com