jak aspekty uporządkują twój kod

16
Aspect-Oriented Programming How can aspects clean your code? Basia Fusińska

Upload: future-processing

Post on 26-May-2015

628 views

Category:

Technology


1 download

DESCRIPTION

Prezentacja Barbary Fusińskiej z III edycji konferencji Quality Excites.

TRANSCRIPT

Page 1: Jak aspekty uporządkują twój kod

Aspect-Oriented Programming

How can aspects clean your code?

Basia Fusińska

Page 2: Jak aspekty uporządkują twój kod

About me

Aspect-Oriented ProgrammingHow can aspects clean your code? 2

@basiafusinska

Programmer

Architect

Coach

Manager

Teacher

Trainer

Page 3: Jak aspekty uporządkują twój kod

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

Page 4: Jak aspekty uporządkują twój kod

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

Page 5: Jak aspekty uporządkują twój kod

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

Page 6: Jak aspekty uporządkują twój kod

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

Page 7: Jak aspekty uporządkują twój kod

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

Page 8: Jak aspekty uporządkują twój kod

How it works?

6How can aspects clean your code?Aspect-Oriented Programming

Page 9: Jak aspekty uporządkują twój kod

Types of advices?

6How can aspects clean your code?Aspect-Oriented Programming

❖ Entry❖ Exit❖ Exception❖ Success❖ Around

❖ Method boundaries vs method interceptions

Page 10: Jak aspekty uporządkują twój kod

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

Page 11: Jak aspekty uporządkują twój kod

9How can aspects clean your code?Aspect-Oriented Programming

Demonstration #1Refactor your way to aspects

Page 12: Jak aspekty uporządkują twój kod

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

Page 13: Jak aspekty uporządkują twój kod

11How can aspects clean your code?Aspect-Oriented Programming

Demonstration #2Some not-so-obvious aspects

Page 14: Jak aspekty uporządkują twój kod

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

Page 15: Jak aspekty uporządkują twój kod

13How can aspects clean your code?Aspect-Oriented Programming

Demonstration #3Testing aspects

Page 16: Jak aspekty uporządkują twój kod

Thank you :)Any questions?

@basiafusinska

getbase.com/careers

[email protected] itblogs.pl/

coldfusion