1 object oriented analysis and design with uml unit 3

66
1 Object Oriented Analysis and Design with UML UNIT 3

Upload: felicity-manning

Post on 01-Jan-2016

226 views

Category:

Documents


5 download

TRANSCRIPT

Page 1: 1 Object Oriented Analysis and Design with UML UNIT 3

1

Object OrientedAnalysis and Design

with UML

UNIT 3

Page 2: 1 Object Oriented Analysis and Design with UML UNIT 3

2

Summary Unit 2...

UML Overview– Model systems using OO concepts

• Information systems, technical systems, system software, real time, distributed system,…

– UML is a modeling language– Based on the notion of views

• Use case, logical, component, concurrency, deployment view

Page 3: 1 Object Oriented Analysis and Design with UML UNIT 3

3

Summary Unit 2...

– UML Diagrams

– Extensibility of the UML• Stereotypes, tagged values, constraints

Use-Case diagram Class diagram Object diagram State diagram Sequence diagram

Collaboration diagram Activity diagram Component diagram Deployment diagram

Page 4: 1 Object Oriented Analysis and Design with UML UNIT 3

4

Summary Unit 2...

Static Modeling with UML– Use Case Diagrams

• to capture the functional requirements of a system

• informally stated in natural language

• focus on what the system is supposed to do

– Class Diagrams• A view of the system in terms of classes and relationships

• Behaviour as well as information in the system is modeled

– This static model of the system is built in a dynamic way !!

Page 5: 1 Object Oriented Analysis and Design with UML UNIT 3

5

Use-Case Diagram

Customer Operator

Return Item

Print Daily Report

Change Item Data

Page 6: 1 Object Oriented Analysis and Design with UML UNIT 3

6

Steps for Building a Use Case Model

Define the boundaries of the system Find the actors and use cases Define the relationships between the use cases Validate and verify the model

– Highly interactive with the end users !

– Should include discussions

Be Creative !

Page 7: 1 Object Oriented Analysis and Design with UML UNIT 3

7

Class Diagram

Page 8: 1 Object Oriented Analysis and Design with UML UNIT 3

8

Relationships Between Classes

An association is a connection between classes A generalization is a relationship between a more

general and a more specific element A dependency is a relationship between elements,

one independent another dependent A refinement is a relationship between two

descriptions of the same thing but at different levels of abstraction

Page 9: 1 Object Oriented Analysis and Design with UML UNIT 3

9

Object Diagram

Page 10: 1 Object Oriented Analysis and Design with UML UNIT 3

10

TheUnified

ModellingLanguage(continued)

UNIT 3

Page 11: 1 Object Oriented Analysis and Design with UML UNIT 3

11

Unit 3 : Outline

Dynamic Modelling– State Diagrams– Sequence Diagrams– Collaboration Diagrams– Activity Diagrams

Page 12: 1 Object Oriented Analysis and Design with UML UNIT 3

12

Dynamic Modeling...

Describes what happens at run-time – Objects vs Classes

How do elements of static diagrams :– Cooperate to manage their tasks– Communicate with each other– Change their state– Provide the functionality of the system

Method outline and messages flow For capturing difficult to understand aspects

Complements

Static Diagrams

Page 13: 1 Object Oriented Analysis and Design with UML UNIT 3

13

Dynamic Modeling.

Focus on communicating one aspect of a system’s dynamics

Model only those elements that are essential Provide detail consistent with the level of

abstraction Sometimes a piece of code says more than

lines, rectangles, ...

Page 14: 1 Object Oriented Analysis and Design with UML UNIT 3

14

Different Dynamic Diagrams

Sequence Diagrams– Focus on time aspect of interaction and

communication

Collaboration Diagrams– Focus on space aspect of interaction and

communication

State Diagrams– Focus on state, behaviour and events

Activity Diagrams– Focus on work aspect of interaction and

communication

Inter-objectrelation

Intra-objectrelation

Page 15: 1 Object Oriented Analysis and Design with UML UNIT 3

15

Unit 3 : Outline

Dynamic Modelling– State Diagrams– Sequence Diagrams– Collaboration Diagrams– Activity Diagrams

Page 16: 1 Object Oriented Analysis and Design with UML UNIT 3

16

State Diagram Symbols

Page 17: 1 Object Oriented Analysis and Design with UML UNIT 3

17

Focus on

The possible states of the instances of a class

The possible transitions from one state to another one

The events firing transitions The operations which are executed within

states or during a transition Intra-objectrelation

Page 18: 1 Object Oriented Analysis and Design with UML UNIT 3

18

Purpose of State diagrams

To document classes that have :– Clearly identifiable states

• State = {ongoing_behaviour, attributes, ...}

– Complex behaviour– Many events (signals)

Page 19: 1 Object Oriented Analysis and Design with UML UNIT 3

19

Notation State Diagrams.

State

State Transition

Initial State

Final State

Page 20: 1 Object Oriented Analysis and Design with UML UNIT 3

20

Parts of a State Diagram

Name

State Variables

Activities

State Box

State Transition

Initial State Final State

Page 21: 1 Object Oriented Analysis and Design with UML UNIT 3

21

Example State Diagram

State Diagramfor the

Elevator Class

Onfirst floor

Movingup

IdleMovingdown

Moving tofirst floor

go up(floor)

Arriveat floor

Arriveat floor

Arriveat first floor

go up(floor)

go down(floor)

time-out

Page 22: 1 Object Oriented Analysis and Design with UML UNIT 3

22

Parts of a State Box

Login

Login time = Current time

Entry/type “login”Exit/login (user name, password)Do/get user nameDo/get passwordHelp/display Help

State Name

State Variables

Activity

Actions

Atomic

Can be further decomposed

Page 23: 1 Object Oriented Analysis and Design with UML UNIT 3

23

Login

Login time = Current time

Entry/type “login”Exit/login (user name, password)Do/get user nameDo/get passwordHelp/display Help

Activities Part of a State Box...

Describes the actions undertaken when the object is in a particular state

These actions are guided by events

Event-name argument-list ‘/’ action-expression

Page 24: 1 Object Oriented Analysis and Design with UML UNIT 3

24

Activities Part of a State Box.

Standard events :

Entry / Action

Exit / Action

Do / Activity

event / Action

Action is executed whenentering the state

Action is executed whenleaving the state

Activity is executed, parametersare allowed

Event is handled withinthe state

Page 25: 1 Object Oriented Analysis and Design with UML UNIT 3

25

State Transition Events…

Four kinds of events in UML :

ChangeEvent

A condition becoming true• shown as a guard condition on a state

transition

Receipt of a message• shown as an event signature on state

transitions

CallEvent

Page 26: 1 Object Oriented Analysis and Design with UML UNIT 3

26

State Transition Events…

TimeEvent

A relative or absolute point in time• shown as a time expression on state

transition

SignalEvent

Signal Event : The receipt of a signal• <<error>> out_of_memory

• keyPressed, …

Page 27: 1 Object Oriented Analysis and Design with UML UNIT 3

27

State Transition Events…

Messages vs Events

modeButton()Display

do/displaycurrent time

Set hours

do/displayhours

Set minutes

do/displayminutes

modeButton()

modeButton()

inc/minutes := minutes +1inc/hours := hours +1

DigitalWatch

modeButton()inc()

Page 28: 1 Object Oriented Analysis and Design with UML UNIT 3

28

State Transition Labels (all optional)event-signature '[' guard-condition ']' '/'

action-expression '^' send-clause

event-signature = event-name '(' parameter ',',... ')'

Examples :– draw(f : Figure, c : Color)

– redraw

– redraw()

– print(invoice)

Page 29: 1 Object Oriented Analysis and Design with UML UNIT 3

29

State Transition Labels…

event-signature '[' guard-condition ']' '/' action-expression '^' send-clause

Guard-condition = A boolean expression placed on a state transition

Examples :– [t = 15sec]

– [number of invoices > n]

– [withdrawal (amount) && balance >= amount ]

Guards are mutual exclusive

Page 30: 1 Object Oriented Analysis and Design with UML UNIT 3

30

State Transition Labels…

event-signature '[' guard-condition ']' '/' action-expression '^' send-clause

Action-expression = Is executed when the transition fires

Examples :– increase () / n := n + 1

– add (n) / sum := sum + n

No nesting orrecursion allowed

Page 31: 1 Object Oriented Analysis and Design with UML UNIT 3

31

State Transition Labels.

event-signature '[' guard-condition ']' '/' action-expression '^' send-clause

Send-clause = Explicit syntax for sending a message during a transition between two states

Examples :– ^ pen.set(color)

– [timer = Time-out] ^ self.go down (first floor)

Page 32: 1 Object Oriented Analysis and Design with UML UNIT 3

32

Example : Digital Watch

modeButton()Display

do/displaycurrent time

Set hours

do/displayhours

Set minutes

do/displayminutes

modeButton()

modeButton()

inc/minutes := minutes +1 modulo 60

inc/hours := hours +1 modulo 24

Page 33: 1 Object Oriented Analysis and Design with UML UNIT 3

33

Communication between Diagrams

Off On

Off On/Stop On/Play

On()

Off()

Off()

On()

Stop()

Play()

On() Off() Stop()Play()

Off()/Stop()

Stop()Play()

CD Player

Remote Control

Page 34: 1 Object Oriented Analysis and Design with UML UNIT 3

34

Substates…

AND-STATES

States that may be true at the same time

Forward Backward

Running

Low speed High speed

Page 35: 1 Object Oriented Analysis and Design with UML UNIT 3

35

Substates.

OR-STATES

States that may not be true at the same time

Forward Backward

Running

Page 36: 1 Object Oriented Analysis and Design with UML UNIT 3

36

Unit 3 : Outline

Dynamic Modelling– State Diagrams– Sequence Diagrams– Collaboration Diagrams– Activity Diagrams

Page 37: 1 Object Oriented Analysis and Design with UML UNIT 3

37

Sequence diagram Symbols

Object 1 Object 2 Object 3

Page 38: 1 Object Oriented Analysis and Design with UML UNIT 3

38

Focus on

The interaction and communication between objects

Specify the realization of an operation or use case

Message sequences Time aspect Cfr Collaboration diagram

Page 39: 1 Object Oriented Analysis and Design with UML UNIT 3

39

Two Available Forms

Generic form– documents all possible alternatives in a scenario– conditions, loops, branches are possible– cfr class diagram

Instance form– documents one possible interaction– no conditions, loops, or branches– cfr object diagram

:Computer

C1:Computeror C1

Page 40: 1 Object Oriented Analysis and Design with UML UNIT 3

40

Different Message Types

Only means of communication with objects are messages

Synchronous

Asynchronous

Simple

Synchronous withImmediate return

Page 41: 1 Object Oriented Analysis and Design with UML UNIT 3

41

Notation Sequence Diagrams…

:Computer :PrintServer :PrinterPrint(ps-file)

Print(ps-file) [no queue]Print(ps-file)

Page 42: 1 Object Oriented Analysis and Design with UML UNIT 3

42

Notation Sequence Diagrams.

:Computer

Print(ps-file)

[no queue]Print(ps-file)

Object

Message send

LifelineActivation

Return

Guard condition

Page 43: 1 Object Oriented Analysis and Design with UML UNIT 3

43

Labels for Iteration

C1:C D1:D D2:Dmessage1()

message2()send message2 until …

message3()

Page 44: 1 Object Oriented Analysis and Design with UML UNIT 3

44

Labels for Constraints

:Computer :PrintServer :PrinterPrint(ps-file)

Print(ps-file)

Print(ps-file)

a

b

b’{b’ – b < 1 sec}

{b - a < 5 sec}

•If PrinterServer receives a file, it should transmit this file to the Printer within 5 sec•Communicating the file from the PrinterServer to the Printer should take less than 1 sec

Page 45: 1 Object Oriented Analysis and Design with UML UNIT 3

45

Object creation

:CustomerWindow

:Customer

NewCustomer(Data)

Customer(Data)

Page 46: 1 Object Oriented Analysis and Design with UML UNIT 3

46

Object Destruction

:CustomerWindow :Customer

RemoveCustomer( )

DeleteCustomer( )

Page 47: 1 Object Oriented Analysis and Design with UML UNIT 3

47

Unit 3 : Outline

Dynamic Modelling– State Diagrams– Sequence Diagrams– Collaboration Diagrams– Activity Diagrams

Page 48: 1 Object Oriented Analysis and Design with UML UNIT 3

48

Collaboration Diagram Symbols

Page 49: 1 Object Oriented Analysis and Design with UML UNIT 3

49

Focus on

The interaction and communication between objects

Shows the static and dynamic relationships between objects – the context aspect

Space aspect(time is no dimension on its own)

Sequence indicated with numbers

Page 50: 1 Object Oriented Analysis and Design with UML UNIT 3

50

Example Collaboration Diagram

:PrinterServer

[printer free] 1.1:Print(ps-file)

:Printer

:Computer

Print(ps-file)

1:Print(ps-file)

Page 51: 1 Object Oriented Analysis and Design with UML UNIT 3

51

Message Flow Labels…

predecessor guard-condition sequence-expression return-value

predecessor = sequence-number ‘,’ … ‘/’

Indicates the assumed message flow before this message may happen

Examples :– 1,2,5 /

– 3 /

Only specify if not implicitly available !

Page 52: 1 Object Oriented Analysis and Design with UML UNIT 3

52

Message Flow Labels…

guard-condition = ‘[‘ condition-clause ‘]’

predecessor guard-condition sequence-expression return-value

Examples :– 1,2,5 / [t = 15sec]

– [number of invoices > n]

– [withdrawal (amount) && balance >= amount]

Page 53: 1 Object Oriented Analysis and Design with UML UNIT 3

53

Message Flow Labels.

predecessor guard-condition sequence-expression return-value

sequence-expression = [integer | name][recurrence] ‘:’

recurrence = ‘*’ ‘[‘ iteration-clause ‘]’

recurrence = ‘[‘ condition-clause ‘]’

Indicates that a message is a part of the actions undertaken in response to another message (referred to with the predecessor number)

Examples :– 1.1 *[x = 1..10]: doSomething()

– 1 [time-out]: display()

Page 54: 1 Object Oriented Analysis and Design with UML UNIT 3

54

Role Names Role Names indicate how the objects know about each other

{Global}

{Local}

{Parameter}

{Self}

The object is known throughout the entire system

The object is knownlocally (temporary object)

The object is known since itwas passed as an argument

The object is referencing itself

{Association}The object is known as an

attribute (default)

Page 55: 1 Object Oriented Analysis and Design with UML UNIT 3

55

Constraints Constraints indicate the objects’ existence during interaction

{New}

{Destroyed}

{Transient}

The object is created during the interaction

The object is destroyed during the interaction

The object will be created and destroyed

Nothing specifiedThe object was available before

the interaction took place

Page 56: 1 Object Oriented Analysis and Design with UML UNIT 3

56

Example : Role names & Constraints

Page 57: 1 Object Oriented Analysis and Design with UML UNIT 3

57

Unit 3 : Outline

Dynamic Modelling– State Diagrams– Sequence Diagrams– Collaboration Diagrams– Activity Diagrams

Page 58: 1 Object Oriented Analysis and Design with UML UNIT 3

58

Activity Diagram Symbols

Page 59: 1 Object Oriented Analysis and Design with UML UNIT 3

59

Focus on

Actions and their results How and when actions are taken What actions actually do Where actions take place (swimlanes) Work aspect Flowcharts featuring parallelism

Page 60: 1 Object Oriented Analysis and Design with UML UNIT 3

60

Purpose of Activity Diagrams

To document :– The actions performed by an operation– The internal working of an object– Make parallelism explicit– A use case

• How is it performed in terms of actions and states?

– Workflow

Page 61: 1 Object Oriented Analysis and Design with UML UNIT 3

61

Notation Activity Diagrams.

Action/Activity

Object Flow

Start State End State

Control Flow

Concurrency Decision State

Page 62: 1 Object Oriented Analysis and Design with UML UNIT 3

62

Example Activity Diagram

Action/Activity

Decision

Initial event

Control Flow(Same label notation as

transitions State Diagram)

ShowMessageBox“Disk full” on

screen

ShowMessageBox“Printing” on

screen

RemoveMessageBox

CreatePostscript

file

[disk full]

[free disk space]

^Printer.print(file)

printFile()

Page 63: 1 Object Oriented Analysis and Design with UML UNIT 3

63

Control Flow

Indicates the order of actions and activities Represented by transition arrows No events on arrow :

– As soon as the execution of the predecessor is finished, the successor is started

Guard conditions are allowed

Page 64: 1 Object Oriented Analysis and Design with UML UNIT 3

64

Decision State / Concurrency

Decision State– Makes alternative sequences explicit

– Complex decisions can be visualized by decision trees

– Outgoing transitions must have mutually exclusive guards

Concurrency– Fork/Join denotes starting/ending point

of concurrent execution

– Combined with guard conditions it formsan alternative to the decision state

Page 65: 1 Object Oriented Analysis and Design with UML UNIT 3

65

Swimlanes

Objects that are

responsible can be

assigned to actions

and activities

Initiate

MeasuringUpdatingDisplayer

Sampler.Run(channel, frequency)

Displayer Sampler

Page 66: 1 Object Oriented Analysis and Design with UML UNIT 3

66

Course Overview.

UML Diagrams Use-Case diagram Class diagram Object diagram State diagram Sequence diagram

Collaboration diagram Activity diagram Component diagram Deployment diagram

Last Unit