Title: Aspect Oriented Software Design
1Aspect Oriented Software Design
- Therapon Skotiniotis Karl Lieberherr
- Northeastern University
- Boston, MA 02115 USA
2The talk will cover ..
- The problem
- code tangling
- The solution
- Better abstractions to provide advanced
Separation of Concerns - The benefits
- Higher code modularity
- Better code reuse
- Ease of program extensions/maintenance/understandi
ng
3The problem
- Readers Writers Protocol
- Multiple Readers
- Single Writer
- Waiting Writers get priority
- Authentication required
class Book // data Book() Message new
StringBuffer("null") public int write (String
msg, int ip) if ((ip 10) gt 0) return 0
else if (AuthClients lt MaxAuthClients)
AuthClients if ((getAReaders() 0)
(getAWriters() 0))
if(getWWriters() gt 0 )
decrWWriters() incrAWriters()
if (getWWriters() 0)
Message.replace(0, Message.length(), msg)
if (getWWriters() gt
0) synchronized (WQueue)
WriteQueue.notify()
else if (getWReaders() gt
0) synchronized (ReadQueue)
ReadQueue.notify()
decrAWriters()
synchronized (AuthQueue)
AuthClients--
AuthQueue.notify()
return 1 else synchronized
(WQueue) WQueue.wait()
else synchronized
(AuthQueue) AuthQueue.wait()
- Enforcing the requirements
- Authentication
- Synchronization
- Scheduling
- Functionality
4Concerns and their Separation
- In Readers Writers
- Functionality
- read(), write()
- Authentication
- Yes, no
- Synchronization
- Resource available or not
- Scheduling
- Policy on who has priority to go next
5Concerns and their Separation (cont)
- In Readers Writers
- Functionality
- read(), write()
- Authentication
- Yes, no
- Synchronization
- Resource available or not
- Scheduling
- Policy on who has priority to go next
Operation
System Constraints
6Concerns and their Separation (cont)
- In OOP, functional decomposition
- has been performed along one
- dimension component.
- Crosscutting concerns are not
- random properties
- Systematically repeated at different
- points within your code
- Affect the semantics and/or
- performance of your system
- AOSD proposes the means to encapsulate
- crosscutting concerns
objects
aspects
7Concerns and their Separation (cont)
- Separation of Concerns Parnas 72 drives
software development. - A concern is a concept, realized as a unit of
software. - Each concern is addressed separately in isolation
- Each concern becomes a module keeping
inter-module dependencies to the minimum - Do not talk to strangers The Law Of Demeter
- There is no established methodology on how to
achieve this principle.
8From this
class Book // data Book() Message new
StringBuffer("null") public int write (String
msg, int ip) if ((ip 10) gt 0) return 0
else if (AuthClients lt MaxAuthClients)
AuthClients if ((getAReaders() 0)
(getAWriters() 0))
if(getWWriters() gt 0 )
decrWWriters() incrAWriters()
if (getWWriters() 0)
Message.replace(0, Message.length(), msg)
if (getWWriters() gt
0) synchronized (WQueue)
WriteQueue.notify()
else if (getWReaders() gt
0) synchronized (ReadQueue)
ReadQueue.notify()
decrAWriters()
synchronized (AuthQueue)
AuthClients--
AuthQueue.notify()
return 1 else synchronized
(WQueue) WQueue.wait()
else synchronized
(AuthQueue) AuthQueue.wait()
- Authentication
- Synchronization
- Scheduling
- Functionality
9 to this
- Authentication
- Synchronization
- Scheduling
- Functionality
10Concerns and their Separation (cont)
Aspect
Base
Aspect
- Authentication
- Synchronization
- Scheduling
- Functionality
Aspect
11Putting it all together
- The program needs to maintain the overall
problem/solution semantics - Code in aspects is only to be executed at
specific execution points - Control (ordering) at this execution points
matters - JoinPoint Model
- Provides the means to identify points within the
execution to which aspectual code can be executed
- Weaving Underlying AOSD tool performs the
integration - At JoinPoints as specified by your code
- Attaching code as specified by your Aspect
- The mechanics behind the JoinPoint make all the
difference - Static Vs Dynamic
- Expressiveness of JoinPoint definition language
- Aspect Code scope and execution capabilities
12Concerns and their Separation (cont)
before if ((getAReaders() 0)
(getAWriters() 0))
if(getWWriters() gt 0 )
decrWWriters() incrAWriters() else
if (getWReaders() gt 0)
synchronized (ReadQueue)
ReadQueue.notify()
after decrAWriters() else synchronized
(WQueue) WQueue.wait()
before if (ip 10 0)
after authenticated --
before if (getWWriters() 0) return true
after if (getWWriters() gt 0) synchronized
(WQueue) WriteQueue.notify()
13Concerns and their Separation (cont)
pointcut call(Book.write())
before if ((getAReaders() 0)
(getAWriters() 0))
if(getWWriters() gt 0 )
decrWWriters() incrAWriters() else
if (getWReaders() gt 0)
synchronized (ReadQueue)
ReadQueue.notify()
after decrAWriters() else synchronized
(WQueue) WQueue.wait()
before if (ip 10 0)
after authenticated --
before if (getWWriters() 0) return true
after if (getWWriters() gt 0) synchronized
(WQueue) WriteQueue.notify()
14Concerns and their Separation (cont)
JoinPoint
pointcut call(Book.write())
before if ((getAReaders() 0)
(getAWriters() 0))
if(getWWriters() gt 0 )
decrWWriters() incrAWriters() else
if (getWReaders() gt 0)
synchronized (ReadQueue)
ReadQueue.notify()
after decrAWriters() else synchronized
(WQueue) WQueue.wait()
before if (ip 10 0)
after authenticated --
before if (getWWriters() 0) return true
after if (getWWriters() gt 0) synchronized
(WQueue) WriteQueue.notify()
15Concerns and their Separation (cont)
pointcut call(Book.write())
1
before if ((getAReaders() 0)
(getAWriters() 0))
if(getWWriters() gt 0 )
decrWWriters() incrAWriters() else
if (getWReaders() gt 0)
synchronized (ReadQueue)
ReadQueue.notify()
after decrAWriters() else synchronized
(WQueue) WQueue.wait()
before if (ip 10 0)
after authenticated --
before if (getWWriters() 0) return true
after if (getWWriters() gt 0) synchronized
(WQueue) WriteQueue.notify()
16Concerns and their Separation (cont)
pointcut call(Book.write())
2
before if ((getAReaders() 0)
(getAWriters() 0))
if(getWWriters() gt 0 )
decrWWriters() incrAWriters() else
if (getWReaders() gt 0)
synchronized (ReadQueue)
ReadQueue.notify()
after decrAWriters() else synchronized
(WQueue) WQueue.wait()
before if (ip 10 0)
after authenticated --
before if (getWWriters() 0) return true
after if (getWWriters() gt 0) synchronized
(WQueue) WriteQueue.notify()
17Concerns and their Separation (cont)
pointcut call(Book.write())
3
before if ((getAReaders() 0)
(getAWriters() 0))
if(getWWriters() gt 0 )
decrWWriters() incrAWriters() else
if (getWReaders() gt 0)
synchronized (ReadQueue)
ReadQueue.notify()
after decrAWriters() else synchronized
(WQueue) WQueue.wait()
before if (ip 10 0)
after authenticated --
before if (getWWriters() 0) return true
after if (getWWriters() gt 0) synchronized
(WQueue) WriteQueue.notify()
18Terminology
- Aspect
- Encapsulation of an aspect as a software entity
- Includes code Advice to be executed at specific
PointCuts - Types of advice
- Before
- After
- Around
- JoinPoint Model
- A means to specify PointCuts
- PointCuts are sets JoinPoints
- JoinPoint a point within the execution of your
base system - Specification of PointCuts can be based on
- Dynamic program information known at runtime
- Static program information known at compile
time
19Aspect Aspect Interaction
- Dependence of Aspectual behavior
- Orthogonal
- No dependence between aspects (Logging and
Scheduling) - Non-Orthogonal
- Dependence between aspects (Synchronization and
Scheduling) - Orthogonal aspects play nice
- Non-orthogonal aspects hinder a protocol between
them - Reuse requires all related dependent aspects
- Alterations in aspects should maintain the
dependence protocol - Alteration of the protocol may require code
alterations throughout all affected aspects
20Benefits
- Better abstractions to capture crosscutting
concerns - Separate development
- Easier means for program extensibility and
evolution - Higher potential for reuse
- Better software quality
- Easier to reason about program behavior
- Closer to Program Design
- PointCuts can be viewed as a generalization of
Aspect/Object interactions - Separation between
- Functional decomposition (OOP)
- Cross-cutting Concerns ( Aspects)
- Evolution towards Plug-and-Play Software
Components and Components of the Shelf (COTS) - Non-invasive program reconfiguration, adaptation,
evolution