Sunteți pe pagina 1din 25

Aspect Oriented Programming

Outline
Introduction
Cross-cutting concerns
Terminology
AOP in action
Under the hood
Performance questions
Pro and Contra

Introduction
Aspect Oriented Programming AOP
Aspect Oriented Software Development - AOSD

What is NOT AOP?


AOP is NOT an academic theory, but a practical
method.

What is NOT AOP?


AOP is NOT a revolution, but an evolution.

What is the certain in


life?

Nothing is certain but death and taxes.

What is the certain in software development?

Nothing is certain but change and complexity.

Outcomes
Change

Frustration on duplicate code

Complexity
I know WHAT to change, but WHERE to change it?
Has my change effect on other components?

Cross-cutting concerns
Functional requirements

vs. Non-functional requiremen

Business rule
Vacations needs to be approved.

Logging

UI design idea
The list of tasks should be
sortable.

Caching

System requirements
Software must run on Windows XP.

Transaction management

Exception handling
Threading
Data validation
Retries
Authentication

In OOP code can cross each other!

Cross-cutting concerns
Concern
reflects the system requirements and the priorities of the
system

Cross-cutting concerns
Outcome
scattered and tangled code

Separation of Concerns

Requirements
ASPECT-ORINENTED
DESING

Business rule 1
Business rule 2
Business rule 3
Logging
Exception Handling
Authentication
Transaction Manageme

Not just a nice theory, but real physical


separation!

Cross-cutting concerns
DEMO
Logging and Exception Handling with AOP

Principles
Dont Repeat Yourself
Ctrl+C, Ctrl+V

Single Responsibility Principle


a class should only have one reason to change

Open/Closed Principle
a class should be open to extension, but closed to
modification

Terminology
Aspect
A program abstraction that defines a cross-cutting concern. It
includes the definition of a pointcut and the advice associated with
that concern.

Advice
The code implementing a concern.

Join Point
An event in an executing program where the advice associated with
an aspect may be executed.

Pointcut
A statement, included in an aspect, that defines the join points
where the associated aspect advice should be executed.

Terminology
DEMO
Aspect, advice, join point, pointcut

AOP in Action
Boundary Aspects
Logging
Data Validation (Defensive Programming)

Exception Aspects
Exception Handling

Interception Aspects
Unreliable Server Connection
Thread-Safe UI

Boundary Aspects
OnMethodBoundaryAspect
OnEntry()
OnExit()
OnSuccess()
OnException()

AOP in Action
DEMO
Data validation with boundary aspects

Exception Aspects
OnExceptionAspect
OnException()

Interception Aspects
MethodInterceptionAspect
OnInvoke()

AOP in Action
Lazy Loading
WPF INotifyPropertyChanged
Transaction Management
Caching
Authentication
Auditing
Licensing
Thread Synchronization
Locking
Undo/Redo

Summary
AOP
simple technique
easy to adapt to existing projects

PostSharp
powerful tool
basic version is free

References
PostSharp
http://www.postsharp.net/

Sommerville
AOSD.net
Vranic

Thank you for your attention!

S-ar putea să vă placă și