how aspects clean your code
DESCRIPTION
Aspect Oriented ProgrammingTRANSCRIPT
Aspect-Oriented Programming
How can aspects clean your code?
@BasiaFusinska
About me
Aspect-Oriented Programming
How can aspects clean your code? 2
@basiafusinska
Programmer
Architect
Coach
Manager
Teacher
Trainer
Agenda
3
❖ What the hell...are aspects?❖ Some examples of AOP❖ Demo 1: refactor your way to aspects❖ Every-day aspects❖ Demo 2: some not-so-obvious aspects❖ How to test aspects❖ Demo 3: testing in practice❖ Q & A
Aspect-Oriented Programming
How can aspects clean your code?
Some history
4
❖ Gregor Kiczales (1997), Xerox PARC❖ OOP is unable to solve some common problems❖ Aspects encapsulate cross-cutting concerns and make them
easier to reuse
Aspect-Oriented Programming
How can aspects clean your code?
Cross cutting concerns
5
❖ Cross-cutting concerns are scattered throughout the code❖ Code becomes difficult to develop and modify❖ Code breaks the Single Responsibility Principle
Aspect-Oriented Programming
How can aspects clean your code?
Cross-cutting concerns are everywhere!
7
❖ Logging❖ Validation❖ Persistence❖ Caching❖ Synchronization❖ Transactions❖ Exception handling❖ Authentication❖ Authorization❖ ...
Aspect-Oriented Programming
How can aspects clean your code?
What the heck are aspects?
6
❖ Purpose: cross-cutting concerns – pieces of functionality used across multiple parts of a system
❖ Job: the advice – code that performs cross-cutting concern❖ Map: pointcut – set of joinpoints❖ How: weaving
Aspect-Oriented Programming
How can aspects clean your code?
How it works?
6Aspect-Oriented Programming
How can aspects clean your code?
Types of advices?
6
❖ Entry❖ Exit❖ Exception❖ Success❖ Around
❖ Method boundaries vs method interceptions
Aspect-Oriented Programming
How can aspects clean your code?
Some benefits of AOP
8
❖ Code is cleaner❖ DRY (Don’t Repeat Yourself): promotes code reuse❖ Better encapsulation
Aspect-Oriented Programming
How can aspects clean your code?
9
Demonstration #1Refactor your way to aspects
Aspect-Oriented Programming
How can aspects clean your code?
You’ve been using AOP without knowing it
10
❖ IHttpModule - requests boundary aspects❖ IActionFilter - code run before and after the action execution❖ ASP.Net MVC Authentication - AuthorizeAttribute❖ Actions per request (Session Open/Close, ORM changes
saving)
Aspect-Oriented Programming
How can aspects clean your code?
11
Demonstration #2Some not-so-obvious aspects
Aspect-Oriented Programming
How can aspects clean your code?
Testing aspects
12
❖ Testing the pointcut – testing if aspects were used in correct places
❖ Testing the advice – testing if the aspects are doing what they are supposed to do
Aspect-Oriented Programming
How can aspects clean your code?
13
Demonstration #3Testing aspects
Aspect-Oriented Programming
How can aspects clean your code?
Thank you :)Any questions?
@basiafusinskabarbarafusinska.
com