Jak aspekty uporządkują twój kod.
-
Upload
future-processing -
Category
Technology
-
view
628 -
download
1
description
Transcript of Jak aspekty uporządkują twój kod.
![Page 1: Jak aspekty uporządkują twój kod.](https://reader036.fdocuments.in/reader036/viewer/2022091118/5563a65ad8b42a2d538b5682/html5/thumbnails/1.jpg)
Aspect-Oriented Programming
How can aspects clean your code?
Basia Fusińska
![Page 2: Jak aspekty uporządkują twój kod.](https://reader036.fdocuments.in/reader036/viewer/2022091118/5563a65ad8b42a2d538b5682/html5/thumbnails/2.jpg)
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.](https://reader036.fdocuments.in/reader036/viewer/2022091118/5563a65ad8b42a2d538b5682/html5/thumbnails/3.jpg)
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.](https://reader036.fdocuments.in/reader036/viewer/2022091118/5563a65ad8b42a2d538b5682/html5/thumbnails/4.jpg)
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.](https://reader036.fdocuments.in/reader036/viewer/2022091118/5563a65ad8b42a2d538b5682/html5/thumbnails/5.jpg)
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.](https://reader036.fdocuments.in/reader036/viewer/2022091118/5563a65ad8b42a2d538b5682/html5/thumbnails/6.jpg)
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.](https://reader036.fdocuments.in/reader036/viewer/2022091118/5563a65ad8b42a2d538b5682/html5/thumbnails/7.jpg)
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.](https://reader036.fdocuments.in/reader036/viewer/2022091118/5563a65ad8b42a2d538b5682/html5/thumbnails/8.jpg)
How it works?
6How can aspects clean your code?Aspect-Oriented Programming
![Page 9: Jak aspekty uporządkują twój kod.](https://reader036.fdocuments.in/reader036/viewer/2022091118/5563a65ad8b42a2d538b5682/html5/thumbnails/9.jpg)
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.](https://reader036.fdocuments.in/reader036/viewer/2022091118/5563a65ad8b42a2d538b5682/html5/thumbnails/10.jpg)
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.](https://reader036.fdocuments.in/reader036/viewer/2022091118/5563a65ad8b42a2d538b5682/html5/thumbnails/11.jpg)
9How can aspects clean your code?Aspect-Oriented Programming
Demonstration #1Refactor your way to aspects
![Page 12: Jak aspekty uporządkują twój kod.](https://reader036.fdocuments.in/reader036/viewer/2022091118/5563a65ad8b42a2d538b5682/html5/thumbnails/12.jpg)
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.](https://reader036.fdocuments.in/reader036/viewer/2022091118/5563a65ad8b42a2d538b5682/html5/thumbnails/13.jpg)
11How can aspects clean your code?Aspect-Oriented Programming
Demonstration #2Some not-so-obvious aspects
![Page 14: Jak aspekty uporządkują twój kod.](https://reader036.fdocuments.in/reader036/viewer/2022091118/5563a65ad8b42a2d538b5682/html5/thumbnails/14.jpg)
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.](https://reader036.fdocuments.in/reader036/viewer/2022091118/5563a65ad8b42a2d538b5682/html5/thumbnails/15.jpg)
13How can aspects clean your code?Aspect-Oriented Programming
Demonstration #3Testing aspects
![Page 16: Jak aspekty uporządkują twój kod.](https://reader036.fdocuments.in/reader036/viewer/2022091118/5563a65ad8b42a2d538b5682/html5/thumbnails/16.jpg)
Thank you :)Any questions?
@basiafusinska
getbase.com/careers
[email protected] itblogs.pl/
coldfusion