Aspect-Oriented
Programming
How can aspects clean your code?
Basia Fusińska
About me
Aspect-Oriented ProgrammingHow 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
How can aspects clean your code?Aspect-Oriented Programming
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
How can aspects clean your code?Aspect-Oriented Programming
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
How can aspects clean your code?Aspect-Oriented Programming
Cross-cutting concerns are everywhere!
7
❖ Logging
❖ Validation
❖ Persistence
❖ Caching
❖ Synchronization
❖ Transactions
❖ Exception handling
❖ Authentication
❖ Authorization
❖ ...
How can aspects clean your code?Aspect-Oriented Programming
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
How can aspects clean your code?Aspect-Oriented Programming
How it works?
6How can aspects clean your code?Aspect-Oriented Programming
Types of advices?
6How can aspects clean your code?Aspect-Oriented Programming
❖ Entry
❖ Exit
❖ Exception
❖ Success
❖ Around
❖ Method boundaries vs method interceptions
Some benefits of AOP
8
❖ Code is cleaner
❖ DRY (Don’t Repeat Yourself): promotes code reuse
❖ Better encapsulation
How can aspects clean your code?Aspect-Oriented Programming
9How can aspects clean your code?Aspect-Oriented Programming
Demonstration #1
Refactor your way to aspects
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)
How can aspects clean your code?Aspect-Oriented Programming
11How can aspects clean your code?Aspect-Oriented Programming
Demonstration #2
Some not-so-obvious aspects
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
How can aspects clean your code?Aspect-Oriented Programming
13How can aspects clean your code?Aspect-Oriented Programming
Demonstration #3
Testing aspects
Thank you :)
Any questions?
@basiafusinska
getbase.com/careers
basia.fusinska@getbase.com
itblogs.pl/coldfusion

Jak aspekty uporządkują twój kod.

  • 1.
    Aspect-Oriented Programming How can aspectsclean your code? Basia Fusińska
  • 2.
    About me Aspect-Oriented ProgrammingHowcan aspects clean your code? 2 @basiafusinska Programmer Architect Coach Manager Teacher Trainer
  • 3.
    Agenda 3 ❖ What thehell...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 How can aspects clean your code?Aspect-Oriented Programming
  • 4.
    Some history 4 ❖ GregorKiczales (1997), Xerox PARC ❖ OOP is unable to solve some common problems ❖ Aspects encapsulate cross-cutting concerns and make them easier to reuse How can aspects clean your code?Aspect-Oriented Programming
  • 5.
    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 How can aspects clean your code?Aspect-Oriented Programming
  • 6.
    Cross-cutting concerns areeverywhere! 7 ❖ Logging ❖ Validation ❖ Persistence ❖ Caching ❖ Synchronization ❖ Transactions ❖ Exception handling ❖ Authentication ❖ Authorization ❖ ... How can aspects clean your code?Aspect-Oriented Programming
  • 7.
    What the heckare 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 How can aspects clean your code?Aspect-Oriented Programming
  • 8.
    How it works? 6Howcan aspects clean your code?Aspect-Oriented Programming
  • 9.
    Types of advices? 6Howcan aspects clean your code?Aspect-Oriented Programming ❖ Entry ❖ Exit ❖ Exception ❖ Success ❖ Around ❖ Method boundaries vs method interceptions
  • 10.
    Some benefits ofAOP 8 ❖ Code is cleaner ❖ DRY (Don’t Repeat Yourself): promotes code reuse ❖ Better encapsulation How can aspects clean your code?Aspect-Oriented Programming
  • 11.
    9How can aspectsclean your code?Aspect-Oriented Programming Demonstration #1 Refactor your way to aspects
  • 12.
    You’ve been usingAOP 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) How can aspects clean your code?Aspect-Oriented Programming
  • 13.
    11How can aspectsclean your code?Aspect-Oriented Programming Demonstration #2 Some not-so-obvious aspects
  • 14.
    Testing aspects 12 ❖ Testingthe pointcut – testing if aspects were used in correct places ❖ Testing the advice – testing if the aspects are doing what they are supposed to do How can aspects clean your code?Aspect-Oriented Programming
  • 15.
    13How can aspectsclean your code?Aspect-Oriented Programming Demonstration #3 Testing aspects
  • 16.
    Thank you :) Anyquestions? @basiafusinska getbase.com/careers basia.fusinska@getbase.com itblogs.pl/coldfusion