Introduction to Software Engineering€¦ · Introduction to Software Engineering (2+1 SWS) Winter...

Preview:

Citation preview

Introduction to Software Engineering (2+1 SWS)Winter Term 2009 / 2010 Dr. Michael EichbergVertretungsprofessur Software EngineeringDepartment of Computer ScienceTechnische Universität Darmstadt

Introduction to Software Engineering

Dr. Michael EichbergFachgebiet Software EngineeringDepartment of Computer ScienceTechnische Universität Darmstadt

UMLInteraction Diagrams• The following slides make extensive use of material from:

Applying UML and Patterns, 3rd Edition; Craig Larman; Prentice Hall

|

Interaction diagrams are used to visualize the interaction via messages between objects; they are used for dynamic object modeling.

UML Interaction Diagrams - Introduction 3

|UML Interaction Diagrams - Introduction 4

Modeling the dynamic behavior is often more rewarding w.r.t. understanding the domain than modeling the static structure.

!

|UML Interaction Diagrams - Introduction 5

Four types of interaction diagrams are available.

•Sequence diagrams(which use a fence format.)•Communication diagrams

(which use a graph or network format)• Timing diagrams (not

further discussed)• Interaction overview

diagrams (not further discussed)

:A myB:Bdo2

do3

do1

E x a m p l e

|UML Interaction Diagrams - Introduction 6

Four types of interaction diagrams are available.

•Sequence diagrams(which use a fence format.)

•Communication diagrams(which use a graph or network format)• Timing diagrams (not

further discussed)• Interaction overview

diagrams (not further discussed)

:A

myB:B

1: do2 ↓2: do3 ↓

do1 →

E x a m p l e

|UML Interaction Diagrams - IntroductionJava Code for Interaction Diagrams

7

:A myB:Bdo2

do3

do1

public class A { private B myB = ...; public void do1() { myB.do2(); myB.do3(); }}

E x a m p l e

|UML Interaction Diagrams - IntroductionJava Code for Interaction Diagrams

8

:A

myB:B

1: do2 ↓2: do3 ↓

do1 →

public class A { private B myB = ...; public void do1() { myB.do2(); myB.do3(); }}

E x a m p l e

|UML Interaction Diagrams - IntroductionJava Code for Interaction Diagrams

9

:A

myB:B

1: do2 ↓2: do3 ↓

do1 →

public class A { private B myB = ...; public void do1() { myB.do2(); myB.do3(); }}

:A myB:Bdo2

do3

public class A { private B myB = ...; public void do1() { myB.do2(); myB.do3(); }}

E x a m p l e

|UML Interaction Diagrams - IntroductionCOMMON NOTATIONS FOR UML INTERACTION DIAGRAMS

10

Lifeline box representing an unnamed instance of class Sale.

:Sale

|UML Interaction Diagrams - IntroductionCOMMON NOTATIONS FOR UML INTERACTION DIAGRAMS

11

Lifeline box representing a named instance (s1) of a instance of Sale.

s1:Sale

|UML Interaction Diagrams - IntroductionCOMMON NOTATIONS FOR UML INTERACTION DIAGRAMS

12

Lifeline box representing the class Font, or more precisely, that Font is an instance of class Class - an instance of a metaclass.

«metaclass»Font

|UML Interaction Diagrams - IntroductionCOMMON NOTATIONS FOR UML INTERACTION DIAGRAMS

13

Lifeline box representing the class Font, or more precisely, that Font is an instance of class Class - an instance of a metaclass.

«metaclass»Font

Class<Font> clazz = Font.class;Corresponding Java Code:

|UML Interaction Diagrams - IntroductionCOMMON NOTATIONS FOR UML INTERACTION DIAGRAMS

14

Lifeline box representing an instance of an ArrayList class, parameterized to hold Sale objects.

sales:ArrayList<Sale>

|UML Interaction Diagrams - IntroductionCOMMON NOTATIONS FOR UML INTERACTION DIAGRAMS

15

Lifeline box representing one instance of class Sale, selected from the sales ArrayList<Sale> collection.

sales[i]:Sale

|UML Interaction Diagrams - IntroductionCOMMON NOTATIONS FOR UML INTERACTION DIAGRAMS

16

sales[i]:Salesales:ArrayList<Sale>

«metaclass»Fonts1:Sale:Sale

O v e r v i e w

|UML Interaction Diagrams - Introduction

COMMON NOTATIONS FOR UML INTERACTION DIAGRAMSFORMAT FOR INTERACTION MESSAGES

17

initialize(code)initialized = getProductDescription (id)d = getProductDescripiton (id : ItemId)d = getProductDescription (id : ItemId) : ProductDescription

E x a m p l e s

“Commonly” Used Grammar:return = message(parameter:parameterType):returnType• Parentheses are usually excluded if there are no parameters.• Type information may be excluded if unimportant.

|UML Interaction Diagrams - Introduction

COMMON NOTATIONS FOR UML INTERACTION DIAGRAMSFORMAT FOR INTERACTION MESSAGES

18

A reply message carrying the return value 96 assigning it to v:v = mymsg(16, variab) : 96

E x a m p l e

UML 2.0 Grammar:<messageident> ::= ([<attribute> ‘=’] <signal-or-operation-name> [‘(‘ [<argument> [‘,’<argument>]* ‘)’] [‘:’ <return-value>]) | ‘*’

Introduction to Software Engineering

Dr. Michael EichbergFachgebiet Software EngineeringDepartment of Computer ScienceTechnische Universität Darmstadt

UMLSequence Diagrams

|UML Sequence DiagramsModeling (Synchronous) Messages

20

:Register :SalegetDate

toString

report

getRegNo

a found message whose sender will not be specified

execution specification bar indicates focus of controldt. Ausführungssequenz

typical synchronous message shown with a filled-arrow line

|UML Sequence DiagramsModeling (Synchronous) Messages

21

:Register :SalegetDate

toString

report

getRegNo

a found message whose sender will not be specified

execution specification bar indicates focus of controldt. Ausführungssequenz

typical synchronous message shown with a filled-arrow lineUML Superstructure

If the Message represents a CallAction, there will normally be a reply message from the called Lifeline back to the calling lifeline before the calling lifeline will proceed.

|UML Sequence Diagrams

Self messages can be modeled using nested execution specification bars.

22

:RegistercancelTransaction

log

self message

|UML Sequence Diagrams

To show the return value of a message you can either use the message syntax (A) or use a message line at the end of an execution specification bar (B).

23

:Register :SaletheReport = report

report

execution specification bar =dt. Ausführungssequenz

:Register :Salereport

report

theReport = report()

V a r i a n t A

V a r i a n t B

|UML Sequence DiagramsObject Instance Creation

24

:Register :SalemakePayment(cashTendered)

create(cashTendered)

authorize

:Payment

Newly created objects are placed at their creation “height”.

The name create is an UML idiom; it is not required.

|UML Sequence DiagramsObject Instance Destruction

25

:Register :SalemakePayment(cashTendered)

create(cashTendered)

...

:Payment

The object destruction notation is also used to mark objects that are no longer usable.

XNot strictly required by the UML.

|UML Sequence DiagramsInvoking Static Methods (Class Methods)

26

:Register«metaclass»

Calendarlocales = getAvailableLocalesreport

|UML Sequence DiagramsInvoking Static Methods (Class Methods)

27

public class Register { public void report() { Locale[] locales = Calendar.getAvailableLocales(); }}

Corresponding Java Code

|

:System:Cashier

enterItem(itemId, quantity)

description, price, total

loop [more items]

UML Sequence Diagrams

Diagram frames in UML sequence diagrams are used to support - among others - conditional and looping constructs.Frames have an operator and a guard.

28

E x a mp l e

Diagramm Frame ~dt. (kombiniertes) Fragment

|UML Sequence Diagrams

Use a UML loop frame to iterate over a collection.29

Modeling task: Calculate the total of a sale by summing up the sub totals for each sales line item.

|UML Sequence Diagrams

Use a UML loop frame to iterate over a collection.30

:Salet = getTotal

st = getSubTotal

lineItems[i] : SalesLineItem

loop (1,lineItems.size)

(min iterations, max iterations)A loop will iterate minimum

the 'minint' number of times and at most the 'maxint' number of

times.

|UML Sequence Diagrams

Use a UML loop frame to iterate over a collection.31

:Salet = getTotal

st = getSubTotal

lineItems[i] : SalesLineItem

[for each item]loop

|UML Sequence Diagrams

Java Code Corresponding to a UML Loop Frame32

public class Sale {

private List<SalesLineItem> lineItems = new ArrayList<SalesLineItem>();

public Money getTotal() { Money t = new Money(); Money st = null; for (SalesLineItem lineItem : lineItems) { st = lineItem.getSubtotal(); t.add (st); } return t; }

}

|UML Sequence Diagrams

Use a UML opt frame to model the sending of a message if the guard condition matches.

33

Modeling task: Get the sum of all sales that happend today after 18:00 o’clock.

|UML Sequence Diagrams

Use a UML opt frame to model the sending of a message if the guard condition matches.

34

:Registerr = getTotal(startDate)

t = getTotal

sales[i] : Sale

[for each sale]loop

opt

date = getDate

[startDate < date]

Frames can be nested.

|UML Sequence Diagrams

Use the UML alt frame to model mutually exclusive alternatives.

35

Modeling task: A register should be able to handle credit card payments and cash payments.

|UML Sequence Diagrams

Use the UML alt frame to model mutually exclusive alternatives.

36

:RegistermakePayment(type,sale)

create

:CreditCardPayment

[type <> CreditCardPayment]alt

:CashPayment

[type <> CashPayment]

create

Object Constraint Language (OCL)

|UML Sequence Diagrams

An interaction occurrence (interaction use) is a reference to an interaction within another interaction.

37

References are used to simplify a diagram and factor out a portion into another diagram or to enable reuse.

Modeling task: We want to calculate the store’s overall total.

|

given

UML Sequence Diagrams

An interaction occurrence (interaction use) is a reference to an interaction within another interaction.

38

:Registerr = getTotal(startDate)

sales[i] : Sale

t = getTotal

[for each sale]loop

opt

date = getDate

[startDate < date]

|

given

UML Sequence Diagrams

An interaction occurrence (interaction use) is a reference to an interaction within another interaction.

39

:Registerr = getTotal(startDate)

t = getTotal

sales[i] : Sale

[for each sale]loop

opt

date = getDate

[startDate < date]

sd CalculatePerRegisterTotal

sd = sequence diagram

|UML Sequence Diagrams

An interaction occurrence (interaction use) is a reference to an interaction within another interaction.

40

:Registerr = getTotal(startDate)

t = getTotal

sales[i] : Sale

[for each sale]loop

opt

date = getDate

[startDate < date]

sd CalculatePerRegisterTotal

|UML Sequence Diagrams

An interaction occurrence (interaction use) is a reference to an interaction within another interaction.

41

:Registerr = getTotal(startDate)

t = getTotal

sales[i] : Sale

[for each sale]loop

opt

date = getDate

[startDate < date]

sd CalculatePerRegisterTotal

:Store :Register

r = getTotal(startDate)

sales[i] : Sale

CalculatePerRegisterTotalref

mr = managementReport

...

|UML Sequence Diagrams

Asynchronous messages are messages that don’t block. An active object is an object where each instance runs on and controls its own thread of execution.

42

Modeling task: The log information should automatically be collected and processed in the background.

|UML Sequence Diagrams

Asynchronous messages are messages that don’t block. An active object is an object where each instance runs on and controls its own thread of execution.

43

Asynchronous messages are shown using stick arrows.

Active objects are modeled using double vertical lines on the left and right side of the lifeline boxes.

:Registercreate

create:LogManager

run

Recommended