Presentation is loading. Please wait.

Presentation is loading. Please wait.

Aspect Oriented Software Design

Similar presentations


Presentation on theme: "Aspect Oriented Software Design"— Presentation transcript:

1 Aspect Oriented Software Design
Therapon Skotiniotis Karl Lieberherr Northeastern University Boston, MA USA 5/24/2019 ABB Workshop

2 The talk will cover .. The problem The solution The benefits
“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/understanding 5/24/2019 ABB Workshop

3 The problem Readers Writers Protocol Multiple Readers Single Writer
class Book: // data Book() {Message = new StringBuffer("null");} public int write (String msg, int ip) { if ((ip % 10) > 0) return 0; else if (AuthClients < MaxAuthClients) { AuthClients++; if ((getAReaders() == 0) && (getAWriters() == 0)) { if(getWWriters() > 0 ) decrWWriters(); incrAWriters(); if (getWWriters() == 0) { Message.replace(0, Message.length(), msg); } if (getWWriters() > 0) synchronized (WQueue) { WriteQueue.notify(); else if (getWReaders() > 0) synchronized (ReadQueue){ ReadQueue.notify(); decrAWriters(); synchronized (AuthQueue) { AuthClients--; AuthQueue.notify(); return 1; else synchronized (WQueue) { WQueue.wait(); else synchronized (AuthQueue) { AuthQueue.wait(); } } Readers Writers Protocol Multiple Readers Single Writer Waiting Writers get priority Authentication required Enforcing the requirements Authentication Synchronization Scheduling Functionality 5/24/2019 ABB Workshop

4 Concerns 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 5/24/2019 ABB Workshop

5 Concerns 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 5/24/2019 ABB Workshop

6 Concerns 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 5/24/2019 ABB Workshop

7 Concerns 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. 5/24/2019 ABB Workshop

8 From this … Authentication Synchronization Scheduling Functionality
class Book: // data Book() {Message = new StringBuffer("null");} public int write (String msg, int ip) { if ((ip % 10) > 0) return 0; else if (AuthClients < MaxAuthClients) { AuthClients++; if ((getAReaders() == 0) && (getAWriters() == 0)) { if(getWWriters() > 0 ) decrWWriters(); incrAWriters(); if (getWWriters() == 0) { Message.replace(0, Message.length(), msg); } if (getWWriters() > 0) synchronized (WQueue) { WriteQueue.notify(); else if (getWReaders() > 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 5/24/2019 ABB Workshop

9 … to this synchronized (AuthQueue) { Authentication Synchronization
if (getWWriters() == 0) { } if (getWWriters() > 0) synchronized (WQueue) { WriteQueue.notify(); class Book: // data Book() {Message = new StringBuffer("null");} public int write (String msg, int ip) { Message.replace(0, Message.length(), msg); return 1; } if ((ip % 10) > 0) return 0; else if (AuthClients < MaxAuthClients) { AuthClients++; synchronized (AuthQueue) { AuthClients--; AuthQueue.notify(); } else synchronized (AuthQueue) { AuthQueue.wait(); if ((getAReaders() == 0) && (getAWriters() == 0)) { if(getWWriters() > 0 ) decrWWriters(); incrAWriters(); else if (getWReaders() > 0) synchronized (ReadQueue){ ReadQueue.notify(); } decrAWriters(); else synchronized (WQueue) { WQueue.wait(); Authentication Synchronization Scheduling Functionality 5/24/2019 ABB Workshop

10 Concerns and their Separation (cont)
if (getWWriters() == 0) { } if (getWWriters() > 0) synchronized (WQueue) { WriteQueue.notify(); class Book: // data Book() {Message = new StringBuffer("null");} public int write (String msg, int ip) { Message.replace(0, Message.length(), msg); return 1; } if ((ip % 10) > 0) return 0; else if (AuthClients < MaxAuthClients) { AuthClients++; synchronized (AuthQueue) { AuthClients--; AuthQueue.notify(); } else synchronized (AuthQueue) { AuthQueue.wait(); Aspect Base Aspect if ((getAReaders() == 0) && (getAWriters() == 0)) { if(getWWriters() > 0 ) decrWWriters(); incrAWriters(); else if (getWReaders() > 0) synchronized (ReadQueue){ ReadQueue.notify(); } decrAWriters(); else synchronized (WQueue) { WQueue.wait(); Authentication Synchronization Scheduling Functionality Aspect 5/24/2019 ABB Workshop

11 Putting 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 5/24/2019 ABB Workshop

12 Concerns and their Separation (cont)
public int write (String msg, int ip) { before: if ((getAReaders() == 0) && (getAWriters() == 0)) { if(getWWriters() > 0 ) decrWWriters(); incrAWriters(); else if (getWReaders() > 0) synchronized (ReadQueue){ ReadQueue.notify(); } after: decrAWriters(); else synchronized (WQueue) { WQueue.wait(); before: if (getWWriters() == 0) { return true; } after: if (getWWriters() > 0) synchronized (WQueue) { WriteQueue.notify(); before: if (ip %10 == 0) { } after: authenticated --; 5/24/2019 ABB Workshop

13 Concerns and their Separation (cont)
pointcut: call(Book.write(…)); public int write (String msg, int ip) { before: if ((getAReaders() == 0) && (getAWriters() == 0)) { if(getWWriters() > 0 ) decrWWriters(); incrAWriters(); else if (getWReaders() > 0) synchronized (ReadQueue){ ReadQueue.notify(); } after: decrAWriters(); else synchronized (WQueue) { WQueue.wait(); before: if (getWWriters() == 0) { return true; } after: if (getWWriters() > 0) synchronized (WQueue) { WriteQueue.notify(); before: if (ip %10 == 0) { } after: authenticated --; 5/24/2019 ABB Workshop

14 Concerns and their Separation (cont)
JoinPoint pointcut: call(Book.write(…)); public int write (String msg, int ip) { before: if ((getAReaders() == 0) && (getAWriters() == 0)) { if(getWWriters() > 0 ) decrWWriters(); incrAWriters(); else if (getWReaders() > 0) synchronized (ReadQueue){ ReadQueue.notify(); } after: decrAWriters(); else synchronized (WQueue) { WQueue.wait(); before: if (getWWriters() == 0) { return true; } after: if (getWWriters() > 0) synchronized (WQueue) { WriteQueue.notify(); before: if (ip %10 == 0) { } after: authenticated --; 5/24/2019 ABB Workshop

15 Concerns and their Separation (cont)
pointcut: call(Book.write(…)); public int write (String msg, int ip) { 1 before: if ((getAReaders() == 0) && (getAWriters() == 0)) { if(getWWriters() > 0 ) decrWWriters(); incrAWriters(); else if (getWReaders() > 0) synchronized (ReadQueue){ ReadQueue.notify(); } after: decrAWriters(); else synchronized (WQueue) { WQueue.wait(); before: if (getWWriters() == 0) { return true; } after: if (getWWriters() > 0) synchronized (WQueue) { WriteQueue.notify(); before: if (ip %10 == 0) { } after: authenticated --; 5/24/2019 ABB Workshop

16 Concerns and their Separation (cont)
pointcut: call(Book.write(…)); public int write (String msg, int ip) { 2 before: if ((getAReaders() == 0) && (getAWriters() == 0)) { if(getWWriters() > 0 ) decrWWriters(); incrAWriters(); else if (getWReaders() > 0) synchronized (ReadQueue){ ReadQueue.notify(); } after: decrAWriters(); else synchronized (WQueue) { WQueue.wait(); before: if (getWWriters() == 0) { return true; } after: if (getWWriters() > 0) synchronized (WQueue) { WriteQueue.notify(); before: if (ip %10 == 0) { } after: authenticated --; 5/24/2019 ABB Workshop

17 Concerns and their Separation (cont)
pointcut: call(Book.write(…)); public int write (String msg, int ip) { 3 before: if ((getAReaders() == 0) && (getAWriters() == 0)) { if(getWWriters() > 0 ) decrWWriters(); incrAWriters(); else if (getWReaders() > 0) synchronized (ReadQueue){ ReadQueue.notify(); } after: decrAWriters(); else synchronized (WQueue) { WQueue.wait(); before: if (getWWriters() == 0) { return true; } after: if (getWWriters() > 0) synchronized (WQueue) { WriteQueue.notify(); before: if (ip %10 == 0) { } after: authenticated --; 5/24/2019 ABB Workshop

18 Terminology Aspect JoinPoint Model
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] 5/24/2019 ABB Workshop

19 Aspect – 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 5/24/2019 ABB Workshop

20 Benefits 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 5/24/2019 ABB Workshop


Download ppt "Aspect Oriented Software Design"

Similar presentations


Ads by Google