Aspect-Oriented 
Programming 
How can aspects clean your code? 
@BasiaFusinska
Aspect-Oriented Programming How can aspects clean your code? 2 
About me 
Programmer 
@basiafusinska 
Architect 
Coach 
Manager 
Teacher 
Trainer
Aspect-Oriented Programming How can aspects clean your code? 
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? 6 
How it works?
Aspect-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
9 
Aspect-Oriented Programming How can aspects clean your code? 
Demonstration #1 
Refactor 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)
11 
Aspect-Oriented Programming How can aspects clean your code? 
Demonstration #2 
Some 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
13 
Aspect-Oriented Programming How can aspects clean your code? 
Demonstration #3 
Testing aspects
Thank you :) 
Any questions? 
@basiafusinska 
barbarafusinska.co 
m

How aspects clean your code

  • 1.
    Aspect-Oriented Programming Howcan aspects clean your code? @BasiaFusinska
  • 2.
    Aspect-Oriented Programming Howcan aspects clean your code? 2 About me Programmer @basiafusinska Architect Coach Manager Teacher Trainer
  • 3.
    Aspect-Oriented Programming Howcan aspects clean your code? 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
  • 4.
    Aspect-Oriented Programming Howcan 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
  • 5.
    Aspect-Oriented Programming Howcan 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
  • 6.
    Aspect-Oriented Programming Howcan aspects clean your code? Cross-cutting concerns are everywhere! 7 ❖ Logging ❖ Validation ❖ Persistence ❖ Caching ❖ Synchronization ❖ Transactions ❖ Exception handling ❖ Authentication ❖ Authorization ❖ ...
  • 7.
    Aspect-Oriented Programming Howcan 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
  • 8.
    Aspect-Oriented Programming Howcan aspects clean your code? 6 How it works?
  • 9.
    Aspect-Oriented Programming Howcan aspects clean your code? Types of advices? 6 ❖ Entry ❖ Exit ❖ Exception ❖ Success ❖ Around ❖ Method boundaries vs method interceptions
  • 10.
    Aspect-Oriented Programming Howcan aspects clean your code? Some benefits of AOP 8 ❖ Code is cleaner ❖ DRY (Don’t Repeat Yourself): promotes code reuse ❖ Better encapsulation
  • 11.
    9 Aspect-Oriented ProgrammingHow can aspects clean your code? Demonstration #1 Refactor your way to aspects
  • 12.
    Aspect-Oriented Programming Howcan 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)
  • 13.
    11 Aspect-Oriented ProgrammingHow can aspects clean your code? Demonstration #2 Some not-so-obvious aspects
  • 14.
    Aspect-Oriented Programming Howcan 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
  • 15.
    13 Aspect-Oriented ProgrammingHow can aspects clean your code? Demonstration #3 Testing aspects
  • 16.
    Thank you :) Any questions? @basiafusinska barbarafusinska.co m