Aspect Oriented Programming
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
Outcomes
Change
Complexity
I know WHAT to change, but WHERE to change it?
Has my change effect on other components?
Cross-cutting concerns
Functional requirements
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
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
Cross-cutting concerns
DEMO
Logging and Exception Handling with AOP
Principles
Dont Repeat Yourself
Ctrl+C, Ctrl+V
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