uml for embedded systems ii. design - eurecomsoc.eurecom.fr/umlemb/course_uml_ii_design.pdf ·  ·...

21
Page 1 UML for Embedded Systems II. Design Ludovic Apvrille [email protected] Eurecom, Office 470 slide 2 Memo on Methodology I. Analysis Use case First class diagram Relevant scenarios II. Design Classes of the system Architecture of the system III. Detailed design Behavior of the system IV. Validation of the system Simulation Code generation (C) Ludovic Apvrille UML for Embedded Systems - Fall 2012

Upload: lydiep

Post on 02-May-2018

225 views

Category:

Documents


6 download

TRANSCRIPT

Page 1: UML for Embedded Systems II. Design - Eurecomsoc.eurecom.fr/UMLEmb/Course_UML_II_Design.pdf ·  · 2017-12-08UML for Embedded Systems II. Design ... Association / Aggregation / Composition

Page 1

UML for Embedded SystemsII. Design

Ludovic [email protected], Office 470

slide 2

Memo on Methodology

I. AnalysisUse case

First class diagramRelevant scenarios

II. DesignClasses of the system

Architecture of the system

III. Detailed designBehavior of the system

IV. Validation of the system

SimulationCode generation

(C) Ludovic Apvrille UML for Embedded Systems - Fall 2012

Page 2: UML for Embedded Systems II. Design - Eurecomsoc.eurecom.fr/UMLEmb/Course_UML_II_Design.pdf ·  · 2017-12-08UML for Embedded Systems II. Design ... Association / Aggregation / Composition

Page 2

slide 3

Design stage

� Purpose• Structure the system under the form of classes and

communication among those classes

� Steps• Identification of secondary classes

- Class diagram

• Identification of relations between classes- Association, aggregation, specialization, etc.

- Class diagram

• Modeling of class hierarchy- Composite structure diagram

• Modeling message exchange between classes- Composite structure diagram

(C) Ludovic Apvrille UML for Embedded Systems - Fall 2012

slide 4

Design

� UML class diagrams� UML composite structure diagrams� Exercises

(C) Ludovic Apvrille UML for Embedded Systems - Fall 2012

Page 3: UML for Embedded Systems II. Design - Eurecomsoc.eurecom.fr/UMLEmb/Course_UML_II_Design.pdf ·  · 2017-12-08UML for Embedded Systems II. Design ... Association / Aggregation / Composition

Page 3

slide 5

UML Class diagrams

� Set of classes� Definition of classes

• Identifier• Stereotype (abstract, interfaces, etc.)• Attributes • Operations

� Relations among classes• Association• Aggregation• Multiplicity

(C) Ludovic Apvrille UML for Embedded Systems - Fall 2012

slide 6

Definition of a Class

BankAccount

- value : Integer-owner-amount- static nextAvailableAccountNb

+credit(Real)+debit(Real)+ static getNextAvailableAccountNb ():Integer

BankAccount

- value : Integer-owner-amount- static nextAvailableAccountNb

+credit(Real)+debit(Real)+ static getNextAvailableAccountNb ():Integer

(C) Ludovic Apvrille UML for Embedded Systems - Fall 2012

Page 4: UML for Embedded Systems II. Design - Eurecomsoc.eurecom.fr/UMLEmb/Course_UML_II_Design.pdf ·  · 2017-12-08UML for Embedded Systems II. Design ... Association / Aggregation / Composition

Page 4

slide 7

Association

(C) Ludovic Apvrille UML for Embedded Systems - Fall 2012

Client Productpurchase

Student

Student

University

UniversitystudyIn

studyIn

University

University

Student

Student

admits

admits

� Association name

� Association with navigability

slide 8

Association (Cont.)

(C) Ludovic Apvrille UML for Embedded Systems - Fall 2012

� Role

Company

Company

Person

Person

worksIn

Boss

worker

worksIn

Boss

worker

Page 5: UML for Embedded Systems II. Design - Eurecomsoc.eurecom.fr/UMLEmb/Course_UML_II_Design.pdf ·  · 2017-12-08UML for Embedded Systems II. Design ... Association / Aggregation / Composition

Page 5

slide 9

Multiplicity

(C) Ludovic Apvrille UML for Embedded Systems - Fall 2012

Company

Company

Person

Person

worksIn

Boss

1..*

worker

0..1 worksIn

Boss

1..*

worker

0..1

1 Exactly one

0..* Zero or more

1..* One or more

0..1 Zero or one

5..8 Specific range (5, 6, 7, or 8)

4..7,9 Combination (4, 5, 6, 7, or 9)

slide 10

Exercise

(C) Ludovic Apvrille UML for Embedded Systems - Fall 2012

� What do you think about this class diagram?

Company

Company

Person

Person

worksIn

Boss

*

worker

1 worksIn

Boss

*

worker

1

Page 6: UML for Embedded Systems II. Design - Eurecomsoc.eurecom.fr/UMLEmb/Course_UML_II_Design.pdf ·  · 2017-12-08UML for Embedded Systems II. Design ... Association / Aggregation / Composition

Page 6

slide 11

More on Associations

(C) Ludovic Apvrille UML for Embedded Systems - Fall 2012

� Multiples associations between the same two classes

� Common error: confusion between message and association name• Only one association is

sufficient to drive the car

Boss

*

passenger1 Boss

*

passenger1

Plane

Plane

Person

Person

1..3

pilot

1 1..3

pilot

1

Person

Person

Car

Car

drive

drive

turnRight

turnRight

StopOnRedLight

StopOnRedLight

slide 12

N-ary Associations

N-ary association

Associative class

Room

LectureStudent

Schedule

(C) Ludovic Apvrille UML for Embedded Systems - Fall 2012

Page 7: UML for Embedded Systems II. Design - Eurecomsoc.eurecom.fr/UMLEmb/Course_UML_II_Design.pdf ·  · 2017-12-08UML for Embedded Systems II. Design ... Association / Aggregation / Composition

Page 7

slide 13

Reflexive Association

CourseManager

Course

manages

1

1..*

Pre-requisite

0..*0..*

(C) Ludovic Apvrille UML for Embedded Systems - Fall 2012

Professor

slide 14

Constraints on Associations

gets a rebate {sale = true}

0..nShop

sale: boolean

Buyer

1..*

(C) Ludovic Apvrille UML for Embedded Systems - Fall 2012

Page 8: UML for Embedded Systems II. Design - Eurecomsoc.eurecom.fr/UMLEmb/Course_UML_II_Design.pdf ·  · 2017-12-08UML for Embedded Systems II. Design ... Association / Aggregation / Composition

Page 8

slide 15

Exercise

� During its studies, a student stays in a room with another student (roommate). A student has some homework to do and some courses and exams to attend. For his / her exam and homework, he / she gets a grade. If this grade is more than 10, the student gets its diploma. Moreover, if he gets a grade over 12, it gets its diploma with distinction.

� Note: use only basics associations

(C) Ludovic Apvrille UML for Embedded Systems - Fall 2012

slide 16

Association / Aggregation / Composition

� Association• Objects are aware of one another so they can work

together� Aggregation

• Control through one object – propagation downward• Protects the integrity of the configuration• Function as a single unit

� Composition• A part may be a member of only one configuration• The part cannot exist outside the configuration

(C) Ludovic Apvrille UML for Embedded Systems - Fall 2012

Page 9: UML for Embedded Systems II. Design - Eurecomsoc.eurecom.fr/UMLEmb/Course_UML_II_Design.pdf ·  · 2017-12-08UML for Embedded Systems II. Design ... Association / Aggregation / Composition

Page 9

Aggregation: Example

� An agent may be a part of no more than one agency, but an agent does not have to be part of an agency (0..1)

� The agency is always comprised of at least one agent but there may be any number of agents

� An agent is considered as an employee of an agency� Every agent is constrained by the fact that he / she must

have a current contract to be an employee of the agency

Agent

Agent

Agency

AgencyMust have a current contractMust have a current contract

employee

0..1

1..*

employee

0..1

1..*

slide 18

Composition

Performance

Performance

Event

Event

0..1

1..*

0..1

1..*

(C) Ludovic Apvrille UML for Embedded Systems - Fall 2012

Page 10: UML for Embedded Systems II. Design - Eurecomsoc.eurecom.fr/UMLEmb/Course_UML_II_Design.pdf ·  · 2017-12-08UML for Embedded Systems II. Design ... Association / Aggregation / Composition

Page 10

slide 19

Aggregation / Composition (Cont.)

MobilePhone

MobilePhone

Microphone

Microphone

1

1

Display

Display

1

1

Speaker

Speaker

1

1

Instructions

Instructions

Warranty

Warranty

Owner

Owner

(C) Ludovic Apvrille UML for Embedded Systems - Fall 2012

slide 20

Generalization / Specialization (Memo)

BankAccount

+computeBalance()

BankAccount

+computeBalance()

CheckingAccount

+computeBalance()

CheckingAccount

+computeBalance()

SavingsAccount

+computeBalance()

SavingsAccount

+computeBalance()

LivretA

+computeBalance()

LivretA

+computeBalance()

(C) Ludovic Apvrille UML for Embedded Systems - Fall 2012

Page 11: UML for Embedded Systems II. Design - Eurecomsoc.eurecom.fr/UMLEmb/Course_UML_II_Design.pdf ·  · 2017-12-08UML for Embedded Systems II. Design ... Association / Aggregation / Composition

Page 11

slide 21

Inheritance

� Inheritance

� Polymorphism

� Abstract / concrete classes

(C) Ludovic Apvrille UML for Embedded Systems - Fall 2012

slide 22

Class Diagram / Object Diagram

Cavier : ProduitDupont : Client

Chocolat : Produit

chaussures : Produit

Durant : Client

Produit Client1..*

#Acheté

1..*

#Acheteur

1..* 1..*

#Acheté #Acheteur

(C) Ludovic Apvrille UML for Embedded Systems - Fall 2012

Page 12: UML for Embedded Systems II. Design - Eurecomsoc.eurecom.fr/UMLEmb/Course_UML_II_Design.pdf ·  · 2017-12-08UML for Embedded Systems II. Design ... Association / Aggregation / Composition

Page 12

slide 23

Design

� UML class diagrams� UML composite structure diagrams� Exercises

(C) Ludovic Apvrille UML for Embedded Systems - Fall 2012

slide 24

Problematic

Are driven wheels associated to the engine of the car?(and not passive wheels…)

Car

Wheel

Engine

e1

e1

w4

w4

isConnectedTo

2

1

isConnectedTo

2

1

(C) Ludovic Apvrille UML for Embedded Systems - Fall 2012

Page 13: UML for Embedded Systems II. Design - Eurecomsoc.eurecom.fr/UMLEmb/Course_UML_II_Design.pdf ·  · 2017-12-08UML for Embedded Systems II. Design ... Association / Aggregation / Composition

Page 13

slide 25

Problematic (Cont.)

(C) Ludovic Apvrille UML for Embedded Systems - Fall 2012

Are the driven wheels of a car associated to the engine of the same car?

Car

Wheel

dw2

dw2

Engine isConnectedTo

21

isConnectedTo

21

e1

e1

Wheel

pw2

pw2

// passive wheels // passive wheels

slide 26

Problematic (Cont.)

(C) Ludovic Apvrille UML for Embedded Systems - Fall 2012

parts

Composite structure diagram1 class Car {1/1}

dw : Wheel[2]

e : Engine[1] / 1

pw : Wheel[2]

Car

Wheel

dw2

dw2

Engine isConnectedTo

21

isConnectedTo

21

e1

e1

Wheel

pw2

pw2

// passive wheels // passive wheels

Internal structure of Car

Page 14: UML for Embedded Systems II. Design - Eurecomsoc.eurecom.fr/UMLEmb/Course_UML_II_Design.pdf ·  · 2017-12-08UML for Embedded Systems II. Design ... Association / Aggregation / Composition

Page 14

slide 27

Composite Structure Diagrams

� Purpose: accurate description of complex systems• Structure of interconnected parts• Run-time structure of interconnected instances

� Basics• Illustrates the internal architecture of classes, and the

interconnections of those classes- Parts- Ports - Signals- Interface

– required– offered

- Connectors between ports

(C) Ludovic Apvrille UML for Embedded Systems - Fall 2012

slide 28

Nested Notation vs. Composition Notation

(C) Ludovic Apvrille UML for Embedded Systems - Fall 2012

class CarArchitecture Diagram {1/1}class CarArchitecture Diagram {1/1}

w : Wheel[4]

w : Wheel[4]

e : Engine[1]

e : Engine[1]axis

axis

package coursStructureCompositeDiagramarchitecture {1/1}package coursStructureCompositeDiagramarchitecture {1/1}

Car

Car

Wheel

Wheel

Engine

Engine

w

4

w

4

e

1

e

1

axis 2 1axis 2 1

parts

Page 15: UML for Embedded Systems II. Design - Eurecomsoc.eurecom.fr/UMLEmb/Course_UML_II_Design.pdf ·  · 2017-12-08UML for Embedded Systems II. Design ... Association / Aggregation / Composition

Page 15

slide 29

Parts

� Difference between a part and an object• An object is a specific instance of a given class

- An object has a kind of serial number 9983-3387-00237

• A part is abstraction of roles played by a set of objects• At execution time, the specific object plays the role

specified by the part� Difference between a part and a class

• A class specifies a structure independently from the context in which it may be used

• A part is a role played by an instance of a class in a given context

(C) Ludovic Apvrille UML for Embedded Systems - Fall 2012

slide 30

Parts Multiplicity

(C) Ludovic Apvrille UML for Embedded Systems - Fall 2012

aircraft : A380

Initial number of instances

Maximum number of instances

1 ?

1 1

2 2

0 255

display : LCD[1]

ap : AutoPilot[2]

call : Call[0..255]

Page 16: UML for Embedded Systems II. Design - Eurecomsoc.eurecom.fr/UMLEmb/Course_UML_II_Design.pdf ·  · 2017-12-08UML for Embedded Systems II. Design ... Association / Aggregation / Composition

Page 16

slide 31

Example of Parts / Objects

(C) Ludovic Apvrille UML for Embedded Systems - Fall 2012

tx : TX[2] rx : RX[2]c1

Net

r t

myNet : Net

tx1 / tx : TX rx1 / rx : RXc1

tx2 / tx : TX rx2 / rx : RXc1

ObjectRole Class

slide 32

Recursive Nested Notation

(C) Ludovic Apvrille UML for Embedded Systems - Fall 2012

package coursStructureCompositeDiagramarchitecture {1/1}package coursStructureCompositeDiagramarchitecture {1/1}

Car

Car

Wheel

Wheel

Engine

Engine

w

4

w

4

e

1

e

1

axis 2 1axis 2 1

Oil

Oil o *

o *

Piston

Piston

p

2..12

p

2..12

class CarArchitecture Diagram {1/1}class CarArchitecture Diagram {1/1}

w : Wheel[4]

w : Wheel[4]

e : Engine[1]

e : Engine[1]axis

axis

class E ng ineA rchitecture D iag ram {1 /1 }class E ng ineA rchitecture D iag ram {1 /1 }

p : P is ton[2 ..12 ]

p : P is ton[2 ..12 ]

o : O il[*]

o : O il[*]

Page 17: UML for Embedded Systems II. Design - Eurecomsoc.eurecom.fr/UMLEmb/Course_UML_II_Design.pdf ·  · 2017-12-08UML for Embedded Systems II. Design ... Association / Aggregation / Composition

Page 17

slide 33

Ports

� Represent a communication point• Junction between a class / object with a connector• No knowledge of what class / object is connected at the

other end of the port� Two types of communications

• Between a class / object and its external environment• Between a class / object and its internal structure

(C) Ludovic Apvrille UML for Embedded Systems - Fall 2012

slide 34

Ports Visibility

� Port = rectangle put along its corresponding class• If it covers the rectangle boundary of its class

- public port

• If it is inside the rectangle of its class but adjacent to the boundary- protected port

class1 class2

(C) Ludovic Apvrille UML for Embedded Systems - Fall 2012

Page 18: UML for Embedded Systems II. Design - Eurecomsoc.eurecom.fr/UMLEmb/Course_UML_II_Design.pdf ·  · 2017-12-08UML for Embedded Systems II. Design ... Association / Aggregation / Composition

Page 18

slide 35

Interfaces

(C) Ludovic Apvrille UML for Embedded Systems - Fall 2012

� A port may• Provide an interface

- Circle

- Input

• Require an interface- Semi circle

- Output

� Interfaces should be declared at class diagram level• Declaration of a list of signals

� Signals should also be declared at class diagram level

slide 36

Example: At Class Diagram Level

package example1Class Diagram {1/1}package example1Class Diagram {1/1}

<<interface>>

toCar

startCar ()stopCar ()gearUp()gearDown ()turnRight ()turnLeft ()

<<interface>>

toCar

startCar ()stopCar ()gearUp()gearDown ()turnRight ()turnLeft ()

<<interface>>

fromCar

failure(Integer)

<<interface>>

fromCar

failure(Integer)

CarSystem

CarSystem

Car

Car

Driver

Driver

c

1

c

1

d

1

d

1

p1p1

toCartoCar

fromCarfromCar

p2p2

fromCarfromCar toCartoCar

(C) Ludovic Apvrille UML for Embedded Systems - Fall 2012

Page 19: UML for Embedded Systems II. Design - Eurecomsoc.eurecom.fr/UMLEmb/Course_UML_II_Design.pdf ·  · 2017-12-08UML for Embedded Systems II. Design ... Association / Aggregation / Composition

Page 19

slide 37

Example: At Composite Structure Diagram Level

active class CarSystemArchitecture Diagram {1/1}active class CarSystemArchitecture Diagram {1/1}

c : Car[1]

c : Car[1]

d : Driver[1]

d : Driver[1]p1p1

toCartoCar

fromCarfromCarp2p2

fromCarfromCar

toCartoCar

Connector

(C) Ludovic Apvrille UML for Embedded Systems - Fall 2012

slide 38

Connectors

� Connecting ports• Interfaces must be “compatible”

� Multiplicity• Not specified -> peer to peer connection• Specified -> star connection

(C) Ludovic Apvrille UML for Embedded Systems - Fall 2012

Page 20: UML for Embedded Systems II. Design - Eurecomsoc.eurecom.fr/UMLEmb/Course_UML_II_Design.pdf ·  · 2017-12-08UML for Embedded Systems II. Design ... Association / Aggregation / Composition

Page 20

slide 39

Example of Connector Multiplicity

tx : TX[2] rx : RX[2]c1

Net

r t

myNet : Net2

tx1 / tx : TX rx1 / rx : RXc1

tx2 / tx : TX rx2 / rx : RXc1

2 2

c1c1

(C) Ludovic Apvrille UML for Embedded Systems - Fall 2012

slide 40

Delegation

The composite class must delegate its request to one of its part

Behavior delegation.theDisplay knows that it communicates with a port, but has no knowledge about the destination part

(C) Ludovic Apvrille UML for Embedded Systems - Fall 2012

Page 21: UML for Embedded Systems II. Design - Eurecomsoc.eurecom.fr/UMLEmb/Course_UML_II_Design.pdf ·  · 2017-12-08UML for Embedded Systems II. Design ... Association / Aggregation / Composition

Page 21

slide 41

Design

� UML class diagrams� UML composite structure diagrams� Exercises

(C) Ludovic Apvrille UML for Embedded Systems - Fall 2012

slide 42

Mobile Phone System

� Apart from its regular components, the mobile phone we wish to design has a integrated camera to take pictures. Pictures can be taken, visualized, deleted, sent via MMS or transferred, via a USB port, to a PC

� Make the system analysis� Design the whole system

• Class diagram• Composite structure diagram

(C) Ludovic Apvrille UML for Embedded Systems - Fall 2012