1 aspekte und modellierung seminar “component and aspect engineering“ ws2003/2004 univ.-prof....
TRANSCRIPT
1
Aspekte und Modellierung
Seminar “Component and Aspect Engineering“WS2003/2004
Univ.-Prof. Dr. Armin B. CremersDr. Günter KnieselDaniel Speicher
Referentin: Anastasija Eifer
2
Gliederung
Einführung Modellierung mit UMLAnwendungsfälle und AspekteObjektorientierte Modellierung mit UMLAspektorientierte Modellierung mit UMLErweiterung von UML für AOMZusammenfassung
3
Einführung (1/2)
Objektorientierte Programmierung und objektorientierteModellierung:
Entwurfsmodelle oft groß und monolithisch die Umsetzung der Anforderungen schwierig zu
verfolgen Entwürfe nicht immer wiederverwendbar und schwer
zu warten
4
Einführung (2/2)
Aspektorientierte Programmierung und aspektorientierteModellierung:
Entwurf und Code hinsichtlich verschiedener Anforderungen zu trennen (separation of concerns)
sog. nichtfunktionale Anforderungen in Aspekten zu kapseln
Modelle stärker entsprechend den Anforderungen zu spezifizieren
bisher kein “Standard“ für die Modellierung
5
Modellierung mit UML
Standard-Objektmodellierungssprache Notationen und Metamodelle
Klassendiagramm Anwendungsfalldiagramm Aktivitätsdiagramm Sequenzdiagramm Zustandsdiagramm Kollaborationsdiagramm Komponentendiagramm Verteilungsdiagramm
6
Modellierung mit UML
Kommunikation klare Darstellung der Konzepte eine Übersicht über das System Konzentration auf die wichtigen Details
Warum Analyse und Entwurf?
7
Modellierung mit UML
Grady Booch, Ivar Jacobson,
Jim Rumbaugh
Ivar Jacobson is a father of the following techniques: use cases, component-based development, the Unified Modeling Language, the Rational Unified Process, and business modelling with use cases and objects. He founded the Swedish company Objectory AB, whichmerged with Rational in 1995. He departed recently from Rational as an employee, but he is still an executive technical consultant of the company.
8
Analysiere Risiko
Preis für Handelbestimmen
Handel festmachen
Grenzen überschritten
Bewertung
<<include>>
<<include>>
Händler
Verkäufer
Abb.1: Anwendungsfalldiagramm (use case diagram)
Anwendungsfälle und Aspekte (1/6)
9
Stammkunde
Kaufe ein Produkt
ErweiterungsstellenZahlungsdatenVersanddaten
<<extend>>
(Zahlungsdaten, Versanddaten)
Abb.2: Erweitert-Beziehung mit Erweiterungsstellen (extension points)
Anwendungsfälle und Aspekte (2/6)
10
join points – die Stellen, an denen Aspekte mit dem normalen Javacode interagieren können
pointcuts – beschreiben joint points und spezifizieren zusätzliche Anweisungen (in advice-Block)
Grundbegriffe von AspectJ:
Anwendungsfälle und Aspekte (3/6)
11
UML-Begriffe Äquivalente AOP- Begriffe
extension aspect
extension points join points
list of extension points
pointcuts
Anwendungsfälle und Aspekte (4/6)
12
Interface
Interface
InterfaceInterface
Cash Withdrawal
Cash Withdrawal
Cash
Cash
CashTransfer Funds Transfer FundsTransfer Funds
Withdraw Cash
Deposit Funds Deposit Funds Deposit Funds
Abb.3: Scattering and Tangling
Use Cases Use Case Realization Components
Anwendungsfälle und Aspekte (5/6)
13
Anwendungsfälle und Aspekte (6/6)
Anwendungsfälle (use cases):
use case realizations und components:
Grundlage für Gespräche zwischen Kunden und Entwicklern repräsentieren externe Perspektive auf das System Mit Hilfe von extensions können Aspekte modelliert werden
repräsentieren interne Struktur des Systems ( design model) im Moment keine Konstrukte für extensions to use-case
realizations und extensions to components in UML
14
Objektorientierte Modellierung mit UML (1/3)
public class Account {
private int balance = 0; public void withdraw (int amount) {...}; public void deposit (int amount) {...}; public int getBalance() {...};
}
public class Customer {
public String name;
// inside some method (a is an account) a.withdraw(50);
}
15
a : Accountc : Customer
1: withdraw(50)
Abb.4: UML-Kollaborationsdiagramm
Objektorientierte Modellierung mit UML (2/3)
16
Customer
-name: String
Account
-balance: int
+withdraw(amount:int)+deposit(amount:int)
ownedAccount
owner
1..*
0..*
Abb.5: UML-Klassendiagramm
Objektorientierte Modellierung mit UML (3/3)
17
pointcut someName : call(Signature);
public aspect Logging { private Log Account.myLog; public void Account.setLog(String fileName) { myLog = new Log(fileName); myLog.println ("This is the logfile for account " + this); }declare parents: Account implements Loggable;
pointcut MethodCall(Customer c, Account a) : call (public * Account.*(..)) && this(c) && target(a); after (Customer c, Account a) : MethodCall(c, a) { a.myLog.println(c + " called " + thisJoinPoint.getSignature().getName()); a.myLog.flush(); }}
Aspektorientierte Modellierung mit UML (1/4)
18
Account
-balance: int
+withdraw(amount:int)+deposit(amount:int)
ownedAccount
owner
1..*
0..*
Customer
-name: String
<<interface>>Loggable
+setLog(fileName:String)
Log
+println()+flush()
0..1
1myLog
Abb.6: Klassendiagramm für Account Logging Aspect
Aspektorientierte Modellierung mit UML (2/4)
19
a : Accountc : Customer
1: withdraw(50)
i : Interceptor
myLog : Log
Abb.7: UML-Kollaborationsdiagramm mit Interceptor
1.1: withdraw(50)
1.2: println(..)1.3: flush(..)
Aspektorientierte Modellierung mit UML (3/4)
20
Nachteile des Modells:
Crosscutting concerns können nicht gut modularisiert werden
Keine explizite Modellierung der Grundmodelle von AspectJ (pointcuts, advice)
Inkonsequenz der Diagramme (kein Interceptor-Objekt im Klassendiagramm)
Der Code muss geändert werden Das Modell zeigt nicht, dass der Account mit oder
ohne logging verwendet werden kann
Aspektorientierte Modellierung mit UML (4/4)
21
c : Customer i : Interceptor a : Account
myLog : Log
1.2: println(..)1.3: flush(..)
1: withdraw(50) 1.1: withdraw(50)
Erweiterung UML für AOM (1/7)
CP1
CP3
CP2
Abb.8: Identifying Connection Points
22
Account
balance: int
+withdraw(amount:int) +deposit(amount:int)
Customer
-name: String
<<aspect>>AccountLogging
-Account::myLog: PrintWriter
+Account::setLog(fileName:String)
Adviceafter(c:Customer, a:Account):methodCall(c,a)
Log
+println(s:String)+flush()
Abb.9: Klassendiagramm für Account Logging Aspect
LogCall
Callpublic void a.myLog.println(“..“);public void a.myLog.flush(..);
<<pointcut>>methodCall
a: Account c: Customer
Call call(public*Account.*(..))&&this(c)
&&target(a);
-myAccount
0..*
<<binding>><<binding>>
<<binding>>
Erweiterung UML für AOM (2/7)
23
Das Klassendiagramm für Account Logging Aspect :
Idee:
Aspekt wird als Komponente modelliert connection points stellen die Schnittstelle des Aspekts dar “binding“-Assoziationen spezifizieren, welche Objekte mit dem Aspekt
verbunden werden können das Einweben wird nicht gezeigt
Definiere Ports von Klassen, um die Schnittstellen der einzelnen Elementen darzustellen
In unserem Beispiel: AccountPort, CustomerPort und LogPort Das Einweben kann gezeigt werden (später im
Konfigurationsmodel)
Erweiterung UML für AOM (3/7)
24
Account
-balance: int
+withdraw(amount:int) +deposit(amount:int)
Customer
-name: String
<<aspect>>AccountLogging
-Account::myLog: PrintWriter
+Account::setLog(fileName:String)
Adviceafter(c:Customer, a:Account): methodCall(c,a)l
Log
+println(s:String) +flush()
Abb.10: Aspekt-Design-Modell
LogCall
Callpublic void a.myLog.println(“..“);public void a.myLog.flush(..);
<<pointcut>>methodCall
a: Account c: Customer
Call call(public*Account.*(..))&&this(c)
&&target(a);
CustomerPort
Requires
+withdraw(amount:int) +deposit(amount:int)
LogPort
Provides+println(s:String) +flush()
Requires
AccountPort
Provides+withdraw(amount:int) +deposit(amount:int)
Requires
-myAccount
0..*
<<binding>><<binding>>
<<binding>>
O O
O
Erweiterung UML für AOM (4/7)
25
:Account
:Log
:Customer<<aspect>>
:AccountLoggingaccountport customerport
accountbinding customerbinding
Outputbinding
logport
Abb.11: Konfigurationsmodell vor dem Einweben
Erweiterung UML für AOM (5/7)
26
a:Account
myLog:Log
c:Customeraport:AccountPort
cport:
CustomerPortlogport:LogPort
Abb.12: Konfigurationsmodell nach dem Einweben
AccountPort
myLog:Log
Provides+withdraw(amount:int) +deposit(amount:int) setLog(fileName:String)
Requires
O
Erweiterung UML für AOM (6/7)
27
:Account
:Log
:Customer
Abb.13: Komposition von Aspekten im Konfigurationsmodell
<<aspect>>:Blocking
<<aspect>>:Logging
Erweiterung UML für AOM (7/7)
28
Zusammenfassung
UML muss für die aspektorientierte Modellierung angepasst werden: geeignete UML-Elemente für AOP-Konstrukte
Das Aspekt-Design-Modell zeigt die statische Struktur des Aspekts
Das Konfigurationsmodell beschreibt, wie der Aspekt in das System eingewoben wird; nach dem Einweben können jetzt zusätzliche Eigenschaften gezeigt werden