43
Introduction to Software Engineering (2+1 SWS) Winter Term 2009 / 2010 Dr. Michael Eichberg Vertretungsprofessur Software Engineering Department of Computer Science Technische Universität Darmstadt

Introduction to Software Engineering€¦ · Introduction to Software Engineering (2+1 SWS) Winter Term 2009 / 2010 Dr. Michael Eichberg Vertretungsprofessur Software Engineering

  • Upload
    others

  • View
    3

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Introduction to Software Engineering€¦ · Introduction to Software Engineering (2+1 SWS) Winter Term 2009 / 2010 Dr. Michael Eichberg Vertretungsprofessur Software Engineering

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

Page 2: Introduction to Software Engineering€¦ · Introduction to Software Engineering (2+1 SWS) Winter Term 2009 / 2010 Dr. Michael Eichberg Vertretungsprofessur Software Engineering

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

Page 3: Introduction to Software Engineering€¦ · Introduction to Software Engineering (2+1 SWS) Winter Term 2009 / 2010 Dr. Michael Eichberg Vertretungsprofessur Software Engineering

|

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

UML Interaction Diagrams - Introduction 3

Page 4: Introduction to Software Engineering€¦ · Introduction to Software Engineering (2+1 SWS) Winter Term 2009 / 2010 Dr. Michael Eichberg Vertretungsprofessur Software Engineering

|UML Interaction Diagrams - Introduction 4

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

!

Page 5: Introduction to Software Engineering€¦ · Introduction to Software Engineering (2+1 SWS) Winter Term 2009 / 2010 Dr. Michael Eichberg Vertretungsprofessur Software Engineering

|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

Page 6: Introduction to Software Engineering€¦ · Introduction to Software Engineering (2+1 SWS) Winter Term 2009 / 2010 Dr. Michael Eichberg Vertretungsprofessur Software Engineering

|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

Page 7: Introduction to Software Engineering€¦ · Introduction to Software Engineering (2+1 SWS) Winter Term 2009 / 2010 Dr. Michael Eichberg Vertretungsprofessur Software Engineering

|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

Page 8: Introduction to Software Engineering€¦ · Introduction to Software Engineering (2+1 SWS) Winter Term 2009 / 2010 Dr. Michael Eichberg Vertretungsprofessur Software Engineering

|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

Page 9: Introduction to Software Engineering€¦ · Introduction to Software Engineering (2+1 SWS) Winter Term 2009 / 2010 Dr. Michael Eichberg Vertretungsprofessur Software Engineering

|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

Page 10: Introduction to Software Engineering€¦ · Introduction to Software Engineering (2+1 SWS) Winter Term 2009 / 2010 Dr. Michael Eichberg Vertretungsprofessur Software Engineering

|UML Interaction Diagrams - IntroductionCOMMON NOTATIONS FOR UML INTERACTION DIAGRAMS

10

Lifeline box representing an unnamed instance of class Sale.

:Sale

Page 11: Introduction to Software Engineering€¦ · Introduction to Software Engineering (2+1 SWS) Winter Term 2009 / 2010 Dr. Michael Eichberg Vertretungsprofessur Software Engineering

|UML Interaction Diagrams - IntroductionCOMMON NOTATIONS FOR UML INTERACTION DIAGRAMS

11

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

s1:Sale

Page 12: Introduction to Software Engineering€¦ · Introduction to Software Engineering (2+1 SWS) Winter Term 2009 / 2010 Dr. Michael Eichberg Vertretungsprofessur Software Engineering

|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

Page 13: Introduction to Software Engineering€¦ · Introduction to Software Engineering (2+1 SWS) Winter Term 2009 / 2010 Dr. Michael Eichberg Vertretungsprofessur Software Engineering

|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:

Page 14: Introduction to Software Engineering€¦ · Introduction to Software Engineering (2+1 SWS) Winter Term 2009 / 2010 Dr. Michael Eichberg Vertretungsprofessur Software Engineering

|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>

Page 15: Introduction to Software Engineering€¦ · Introduction to Software Engineering (2+1 SWS) Winter Term 2009 / 2010 Dr. Michael Eichberg Vertretungsprofessur Software Engineering

|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

Page 16: Introduction to Software Engineering€¦ · Introduction to Software Engineering (2+1 SWS) Winter Term 2009 / 2010 Dr. Michael Eichberg Vertretungsprofessur Software Engineering

|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

Page 17: Introduction to Software Engineering€¦ · Introduction to Software Engineering (2+1 SWS) Winter Term 2009 / 2010 Dr. Michael Eichberg Vertretungsprofessur Software Engineering

|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.

Page 18: Introduction to Software Engineering€¦ · Introduction to Software Engineering (2+1 SWS) Winter Term 2009 / 2010 Dr. Michael Eichberg Vertretungsprofessur Software Engineering

|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>]) | ‘*’

Page 19: Introduction to Software Engineering€¦ · Introduction to Software Engineering (2+1 SWS) Winter Term 2009 / 2010 Dr. Michael Eichberg Vertretungsprofessur Software Engineering

Introduction to Software Engineering

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

UMLSequence Diagrams

Page 20: Introduction to Software Engineering€¦ · Introduction to Software Engineering (2+1 SWS) Winter Term 2009 / 2010 Dr. Michael Eichberg Vertretungsprofessur Software Engineering

|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

Page 21: Introduction to Software Engineering€¦ · Introduction to Software Engineering (2+1 SWS) Winter Term 2009 / 2010 Dr. Michael Eichberg Vertretungsprofessur Software Engineering

|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.

Page 22: Introduction to Software Engineering€¦ · Introduction to Software Engineering (2+1 SWS) Winter Term 2009 / 2010 Dr. Michael Eichberg Vertretungsprofessur Software Engineering

|UML Sequence Diagrams

Self messages can be modeled using nested execution specification bars.

22

:RegistercancelTransaction

log

self message

Page 23: Introduction to Software Engineering€¦ · Introduction to Software Engineering (2+1 SWS) Winter Term 2009 / 2010 Dr. Michael Eichberg Vertretungsprofessur Software Engineering

|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

Page 24: Introduction to Software Engineering€¦ · Introduction to Software Engineering (2+1 SWS) Winter Term 2009 / 2010 Dr. Michael Eichberg Vertretungsprofessur Software Engineering

|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.

Page 25: Introduction to Software Engineering€¦ · Introduction to Software Engineering (2+1 SWS) Winter Term 2009 / 2010 Dr. Michael Eichberg Vertretungsprofessur Software Engineering

|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.

Page 26: Introduction to Software Engineering€¦ · Introduction to Software Engineering (2+1 SWS) Winter Term 2009 / 2010 Dr. Michael Eichberg Vertretungsprofessur Software Engineering

|UML Sequence DiagramsInvoking Static Methods (Class Methods)

26

:Register«metaclass»

Calendarlocales = getAvailableLocalesreport

Page 27: Introduction to Software Engineering€¦ · Introduction to Software Engineering (2+1 SWS) Winter Term 2009 / 2010 Dr. Michael Eichberg Vertretungsprofessur Software Engineering

|UML Sequence DiagramsInvoking Static Methods (Class Methods)

27

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

Corresponding Java Code

Page 28: Introduction to Software Engineering€¦ · Introduction to Software Engineering (2+1 SWS) Winter Term 2009 / 2010 Dr. Michael Eichberg Vertretungsprofessur Software Engineering

|

: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

Page 29: Introduction to Software Engineering€¦ · Introduction to Software Engineering (2+1 SWS) Winter Term 2009 / 2010 Dr. Michael Eichberg Vertretungsprofessur Software Engineering

|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.

Page 30: Introduction to Software Engineering€¦ · Introduction to Software Engineering (2+1 SWS) Winter Term 2009 / 2010 Dr. Michael Eichberg Vertretungsprofessur Software Engineering

|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.

Page 31: Introduction to Software Engineering€¦ · Introduction to Software Engineering (2+1 SWS) Winter Term 2009 / 2010 Dr. Michael Eichberg Vertretungsprofessur Software Engineering

|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

Page 32: Introduction to Software Engineering€¦ · Introduction to Software Engineering (2+1 SWS) Winter Term 2009 / 2010 Dr. Michael Eichberg Vertretungsprofessur Software Engineering

|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; }

}

Page 33: Introduction to Software Engineering€¦ · Introduction to Software Engineering (2+1 SWS) Winter Term 2009 / 2010 Dr. Michael Eichberg Vertretungsprofessur Software Engineering

|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.

Page 34: Introduction to Software Engineering€¦ · Introduction to Software Engineering (2+1 SWS) Winter Term 2009 / 2010 Dr. Michael Eichberg Vertretungsprofessur Software Engineering

|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.

Page 35: Introduction to Software Engineering€¦ · Introduction to Software Engineering (2+1 SWS) Winter Term 2009 / 2010 Dr. Michael Eichberg Vertretungsprofessur Software Engineering

|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.

Page 36: Introduction to Software Engineering€¦ · Introduction to Software Engineering (2+1 SWS) Winter Term 2009 / 2010 Dr. Michael Eichberg Vertretungsprofessur Software Engineering

|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)

Page 37: Introduction to Software Engineering€¦ · Introduction to Software Engineering (2+1 SWS) Winter Term 2009 / 2010 Dr. Michael Eichberg Vertretungsprofessur Software Engineering

|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.

Page 38: Introduction to Software Engineering€¦ · Introduction to Software Engineering (2+1 SWS) Winter Term 2009 / 2010 Dr. Michael Eichberg Vertretungsprofessur Software Engineering

|

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]

Page 39: Introduction to Software Engineering€¦ · Introduction to Software Engineering (2+1 SWS) Winter Term 2009 / 2010 Dr. Michael Eichberg Vertretungsprofessur Software Engineering

|

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

Page 40: Introduction to Software Engineering€¦ · Introduction to Software Engineering (2+1 SWS) Winter Term 2009 / 2010 Dr. Michael Eichberg Vertretungsprofessur Software Engineering

|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

Page 41: Introduction to Software Engineering€¦ · Introduction to Software Engineering (2+1 SWS) Winter Term 2009 / 2010 Dr. Michael Eichberg Vertretungsprofessur Software Engineering

|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

...

Page 42: Introduction to Software Engineering€¦ · Introduction to Software Engineering (2+1 SWS) Winter Term 2009 / 2010 Dr. Michael Eichberg Vertretungsprofessur Software Engineering

|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.

Page 43: Introduction to Software Engineering€¦ · Introduction to Software Engineering (2+1 SWS) Winter Term 2009 / 2010 Dr. Michael Eichberg Vertretungsprofessur Software Engineering

|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