Welcome to Scribd. Sign in or start your free trial to enjoy unlimited e-books, audiobooks & documents.Find out more
Download
Standard view
Full view
of .
Look up keyword
Like this
1Activity
0 of .
Results for:
No results containing your search query
P. 1
Aspect Oriented Programming With C++ and Aspect C++

Aspect Oriented Programming With C++ and Aspect C++

Ratings:
(0)
|Views: 14|Likes:
Published by api-26411618

More info:

Published by: api-26411618 on Oct 18, 2008
Copyright:Attribution Non-commercial

Availability:

Read on Scribd mobile: iPhone, iPad and Android.
download as PDF, TXT or read online from Scribd
See more
See less

03/18/2014

pdf

text

original

\u00a9 2005 Daniel Lohmann and Olaf Spinczyk
I/1
Introduction
University of Erlangen-Nuremberg
Computer Science 4
Aspect-Oriented Programming
Aspect-Oriented Programming
with
with
C++ and AspectC++
C++ and AspectC++
AOSD 2005 Tutorial
AOSD 2005 Tutorial
\u00a9 2005 Daniel Lohmann and Olaf Spinczyk
I/2
Introduction
Presenters
\u27a2Daniel Lohmann
dl@aspectc.org
\u2013University of Erlangen-Nuremberg, Germany
\u27a2Olaf Spinczyk
os@aspectc.org
\u2013University of Erlangen-Nuremberg, Germany
\u00a9 2005 Daniel Lohmann and Olaf Spinczyk
I/3
Introduction
Schedule
Part Title
Time
I
Introduction
10m
II AOP with pure C++
40m
III AOP with AspectC++
70m
IV Tool support for AspectC++
30m
V Real-World Examples
20m
VI Summary and Discussion
10m
\u00a9 2005 Daniel Lohmann and Olaf Spinczyk
I/4
Introduction
This Tutorial is about ...
\u27a2Writing aspect-oriented code with pure C++
\u2013
basic implementation techniques using C++ idioms
\u2013
limitations of the pure C++ approach
\u27a2Programming withA spec tC+ +
\u2013
language concepts, implementation, tool support
\u2013
this is an AspectC++ tutorial
\u27a2Programming languages and concepts
\u2013no coverage of other AOSD topics like analysis or design
\u00a9 2005 Daniel Lohmann and Olaf Spinczyk
I/5
Introduction
Aspect-Oriented Programming
\u27a2AOP is about modularizing crosscutting concerns
\u27a2Examples: tracing, synchronization, security,
buffering, error handling, constraint checks, ...
badly modularized
well modularized concern
without AOP
with AOP
aspect
\u00a9 2005 Daniel Lohmann and Olaf Spinczyk
I/6
Introduction
Why AOP with C++?
\u27a2Widely accepted benefits from using AOP
\ue000avoidance of code redundancy, better reusability,
maintainability, configurability, the code better reflects the
design, ...
\u27a2Enormous existing C++ code base
\ue000maintainance: extensions are often crosscutting
\u27a2Millions of programmers use C++
\ue000for many domains C++ isthe adequate language
\ue000they want to benefit from AOP (as Java programmers do)
\u27a2How can the AOP community help?
\ue000Part II: describe how to apply AOP with built-in
mechanisms
\ue000Part III-V: provide special language mechanisms for AOP
\u00a9 2005 Daniel Lohmann and Olaf Spinczyk
I/7
Introduction
Scenario: A Queue utility class
\u00a9 2005 Daniel Lohmann and Olaf Spinczyk
I/8
Introduction
The Simple Queue Class
namespace util {
class Item {
friend classQueue;
Item* next;
public:
Item() : next(0){}
};
class Queue {
Item* first;
Item* last;
public:
Queue() : first(0), last(0) {}
void enqueue( Item* item ) {
printf( " > Queue::enqueue()\n" );
if( last ) {
last->next = item;
last = item;
} else
last = first = item;
printf( " < Queue::enqueue()\n" );
}

Item* dequeue() {
printf(" > Queue::dequeue()\n");
Item* res = first;

if( first == last )
first = last = 0;
else
first = first->next;
printf(" < Queue::dequeue()\n");
returnres;
}
}; // class Queue
} // namespace util
\u00a9 2005 Daniel Lohmann and Olaf Spinczyk
I/9
Introduction
Scenario: The Problem

Please extend the
Queue class by an
element counter!

I want Queue to
throw exceptions!
Queue should be
thread-safe!
Various users of Queue demand extensions:
\u00a9 2005 Daniel Lohmann and Olaf Spinczyk
I/10
Introduction
The Not So Simple Queue Class
class Queue {
Item *first, *last;
intcounter;
os::Mutex lock;
public:
Queue () : first(0), last(0) {
counter = 0;
}void enqueue(Item* item) {
lock.enter();
try{
if (item == 0)
throwQueueInvalidItemError();
if (last) {
last->next = item;

last = item;
}else { last = first = item; }
++counter;

}catch (...) {
lock.leave();throw;
}lock.leave();
}

Item* dequeue() {
Item* res;
lock.enter();

try{
res = first;
if (first == last)
first = last = 0;
else first = first->next;
if (counter > 0) \u2013counter;
if (res == 0)
throwQueueEmptyError();
}catch (...) {
lock.leave();
throw;
}lock.leave();
returnres;
}int count() { return counter; }
}; // class Queue
\u00a9 2005 Daniel Lohmann and Olaf Spinczyk
I/11
Introduction
What Code Does What?
class Queue {
Item *first, *last;
intcounter;
os::Mutex lock;
public:
Queue () : first(0), last(0) {
counter = 0;
}void enqueue(Item* item) {
lock.enter();
try{
if (item == 0)
throwQueueInvalidItemError();
if (last) {
last->next = item;

last = item;
}else { last = first = item; }
++counter;

}catch (...) {
lock.leave();throw;
}lock.leave();
}

Item* dequeue() {
Item* res;
lock.enter();

try{
res = first;
if (first == last)
first = last = 0;
else first = first->next;
if (counter > 0) \u2013counter;
if (res == 0)
throwQueueEmptyError();
}catch (...) {
lock.leave();
throw;
}lock.leave();
returnres;
}int count() { return counter; }
}; // class Queue
\u00a9 2005 Daniel Lohmann and Olaf Spinczyk
I/12
Introduction
Problem Summary
The component code is \u201cpolluted\u201d with code for several
logically independent concerns, thus it is ...
\u27a2hard tow rite the code
\u2013
many different things have to be considered simultaneously
\u27a2hard torea d the code
\u2013
many things are going on at the same time
\u27a2hard tom ain tain andevo lve the code
\u2013
the implementation of concerns such as locking isscattered
over the entire source base (a \u201ccrosscutting concern\u201d)
\u27a2hard toco n fig ure at compile time
\u2013
the users get a \u201cone fits all\u201d queue class

You're Reading a Free Preview

Download
scribd
/*********** DO NOT ALTER ANYTHING BELOW THIS LINE ! ************/ var s_code=s.t();if(s_code)document.write(s_code)//-->