chapter 5: analysis part i: object modeling part ii: dynamic modeling qutaibah malluhi software...

70
Chapter 5: Analysis Part I: Object Modeling Part II: Dynamic Modeling Qutaibah Malluhi Software Engineering Qatar University Based on slides by Bernd Bruegge & Allen H. Dutoit

Post on 20-Jan-2016

228 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Chapter 5: Analysis Part I: Object Modeling Part II: Dynamic Modeling Qutaibah Malluhi Software Engineering Qatar University Based on slides by Bernd

Chapter 5: AnalysisPart I: Object ModelingPart II: Dynamic Modeling

Qutaibah MalluhiSoftware EngineeringQatar University

Based on slides by Bernd Bruegge & Allen H. Dutoit

Page 2: Chapter 5: Analysis Part I: Object Modeling Part II: Dynamic Modeling Qutaibah Malluhi Software Engineering Qatar University Based on slides by Bernd

Introduction

Page 3: Chapter 5: Analysis Part I: Object Modeling Part II: Dynamic Modeling Qutaibah Malluhi Software Engineering Qatar University Based on slides by Bernd

Summary of Previous Discussion

Pure functional decomposition is bad:Leads to unmaintainable code

Pure object identification is bad:May lead to wrong objects, wrong attributes,

wrong methods

Page 4: Chapter 5: Analysis Part I: Object Modeling Part II: Dynamic Modeling Qutaibah Malluhi Software Engineering Qatar University Based on slides by Bernd

Ambiguity: what do you see?

Page 5: Chapter 5: Analysis Part I: Object Modeling Part II: Dynamic Modeling Qutaibah Malluhi Software Engineering Qatar University Based on slides by Bernd

General Approach for Identifying Objects

The key to successful analysis:Start with use cases and then find the

participating objects If somebody asks “What is this?”, do not

answer right away. Return the question or observe the end user: “What is it used for?”

Identify system boundary What object is inside, what object is outside?

Page 6: Chapter 5: Analysis Part I: Object Modeling Part II: Dynamic Modeling Qutaibah Malluhi Software Engineering Qatar University Based on slides by Bernd

From Use Cases to ObjectsLevel 1 Use Case

Level 2 Use Cases

Level 3 Use Cases

Operations

ParticipatingObjects

Level 2

Level 1

Level 2

Level 3 Level 3

Level 4 Level 4

Level 3

A B

Page 7: Chapter 5: Analysis Part I: Object Modeling Part II: Dynamic Modeling Qutaibah Malluhi Software Engineering Qatar University Based on slides by Bernd

Why Functional Decomposition is not Enough

Scenarios

Level 1 Use Cases

Level 2 Use Cases

Operations

ParticipatingObjects

Level 2

Level 1

Level 2

Level 3 Level 3

Level 4 Level 4

Level 3

A B

Page 8: Chapter 5: Analysis Part I: Object Modeling Part II: Dynamic Modeling Qutaibah Malluhi Software Engineering Qatar University Based on slides by Bernd

Analysis Overview

Page 9: Chapter 5: Analysis Part I: Object Modeling Part II: Dynamic Modeling Qutaibah Malluhi Software Engineering Qatar University Based on slides by Bernd

Introduction

Requirements

Design

Implementation

Testing

Analysis

System Arch. Design

Detailed Design

Page 10: Chapter 5: Analysis Part I: Object Modeling Part II: Dynamic Modeling Qutaibah Malluhi Software Engineering Qatar University Based on slides by Bernd

Object Oriented Analysis (Modeling)

Requirement elicitation leads to requirements specifications Functional model (use-case and scenarios) Non-functional requirements and constraints

Analysis focuses on producing a model of the system – analysis model

Analysis model is composed of 2 individual models analysis object model (class and object diagram) dynamic model (statechart, sequence diagrams)

Page 11: Chapter 5: Analysis Part I: Object Modeling Part II: Dynamic Modeling Qutaibah Malluhi Software Engineering Qatar University Based on slides by Bernd

Analysis Phase

Inputs - requirements specifications (use cases) Outputs the components of the Analysis Model

dynamic model Develop preliminary sequence diagrams to illustrate the

interaction between objects Develop state diagrams for objects with interesting behavior

static model Analysis object model Develop preliminary object and class diagrams showing the

structure of the system

Heuristics to help create the Analysis Model

Page 12: Chapter 5: Analysis Part I: Object Modeling Part II: Dynamic Modeling Qutaibah Malluhi Software Engineering Qatar University Based on slides by Bernd

Requirements Model, Analysis Model, Design Models 1. Analyze the problem statement

Identify functional requirements Identify nonfunctional requirements Identify constraints (pseudo requirements)

2. Build the functional model Develop use cases to illustrate functionality requirements

3. Build the dynamic model Develop sequence diagrams to illustrate the interaction between objects Develop state diagrams for objects with interesting behavior

4. Build the static model Develop object and class diagrams showing the structure of the system

5. Use the analysis model (static and dynamic) to create system (architecture) design model, and detailed object design model

Page 13: Chapter 5: Analysis Part I: Object Modeling Part II: Dynamic Modeling Qutaibah Malluhi Software Engineering Qatar University Based on slides by Bernd

Figure 5-2, Products of requirements elicitation and analysis.

Analysis

functionalmodel

nonfunctionalrequirements

analysis objectmodel

Requirementselicitation

dynamic model

Requirements

Analysis Model

Specification

System design

Object design

Page 14: Chapter 5: Analysis Part I: Object Modeling Part II: Dynamic Modeling Qutaibah Malluhi Software Engineering Qatar University Based on slides by Bernd

Object Modeling

Page 15: Chapter 5: Analysis Part I: Object Modeling Part II: Dynamic Modeling Qutaibah Malluhi Software Engineering Qatar University Based on slides by Bernd

Outline

Activities during object modeling Object identification Object types

entity, boundary and control objects

Object naming Abbott’s technique helps in object identification Users of class diagrams

Page 16: Chapter 5: Analysis Part I: Object Modeling Part II: Dynamic Modeling Qutaibah Malluhi Software Engineering Qatar University Based on slides by Bernd

Activities during Object Modeling

Main goal: Find the important abstractions What happens if we find the wrong abstractions?

Iterate and correct the model

Steps during object modeling1. Class identification

Based on the fundamental assumption that we can find abstractions

2. Find the attributes

3. Find the methods

4. Find the associations between classes

Order of steps Goal: get the desired abstractions Order of steps secondary, only a heuristic Iteration is important

Page 17: Chapter 5: Analysis Part I: Object Modeling Part II: Dynamic Modeling Qutaibah Malluhi Software Engineering Qatar University Based on slides by Bernd

Class Identification

Identify the boundaries of the system Identify the important entities in the system Class identification is crucial to object-oriented

modeling Should be able to:

1. Find the classes for a new software system (Forward Engineering)

2. Identify the classes in an existing system (Reverse Engineering)

Page 18: Chapter 5: Analysis Part I: Object Modeling Part II: Dynamic Modeling Qutaibah Malluhi Software Engineering Qatar University Based on slides by Bernd

Pieces of an Object Model

Classes Associations (Relations)

Generic associations Canonical associations

Part of- Hierarchy (Aggregation) Kind of-Hierarchy (Generalization)

Attributes Application specific Attributes in one system can be classes in another system

Operations Generic operations: Get/Set, General world knowledge, design

patterns Domain operations: Dynamic model, Functional model

Page 19: Chapter 5: Analysis Part I: Object Modeling Part II: Dynamic Modeling Qutaibah Malluhi Software Engineering Qatar University Based on slides by Bernd

Object vs. Class

Object (instance): Exactly one thing This lecture on Software Engineering on November 15 from 14:30 -

16:00 A class describes a group of objects with similar properties

Game, Tournament, mechanic, car, database Object diagram: A graphic notation for modeling objects, classes and

their relationships ("associations"): Class diagram: Template for describing many instances of data. Useful

for taxonomies, patters, schemata... Instance diagram: A particular set of objects relating to each other. Useful

for discussing scenarios, test cases and examples

Page 20: Chapter 5: Analysis Part I: Object Modeling Part II: Dynamic Modeling Qutaibah Malluhi Software Engineering Qatar University Based on slides by Bernd

Finding Classes from Use Cases

The analysis activities are guided by heuristics Quality of output very much depends on experience

Heuristics for identifying objects Find terms that developers or users need to clarify in order to understand the flow

of events Look for recurring nouns (e.g., Incident), Identify real world entities that the system needs to keep track of (e.g., FieldOfficer,

Dispatcher, Resource), Identify real world procedures that the system needs to keep track of (e.g.,

EmergencyOperationsPlan), Identify data sources or sinks (e.g., Printer)

Be prepared that some objects are still missing and need to be found: Refine when you model flow of events with a sequence diagram

Always use the user’s terms

Page 21: Chapter 5: Analysis Part I: Object Modeling Part II: Dynamic Modeling Qutaibah Malluhi Software Engineering Qatar University Based on slides by Bernd

Object Types

Entity Objects Represent the persistent information tracked by the system (Application

domain objects, “Business objects”) Boundary Objects

Represent the interaction between the user and the system Control Objects:

Represent the control tasks performed by the system In charge of realizing use cases

Having three types of objects leads to models that are more resilient to change. The interface of a system changes more likely than the control The control of the system change more likely than the application domain

Concept is similar to Model, View, Controller design pattern Model, View, Controller (MVC)

Page 22: Chapter 5: Analysis Part I: Object Modeling Part II: Dynamic Modeling Qutaibah Malluhi Software Engineering Qatar University Based on slides by Bernd

Example: 2BWatch Objects

Year

Month

Day

ChangeDateButton

LCDDisplay

Entity Objects Control Objects Interface Objects

Page 23: Chapter 5: Analysis Part I: Object Modeling Part II: Dynamic Modeling Qutaibah Malluhi Software Engineering Qatar University Based on slides by Bernd

Naming of Object Types in UML

UML provides several mechanisms to extend the language UML provides the stereotype mechanism to present new modeling

elements Stereotypes can be used to distinguish different object types

<<Entity>>Year

<<Entity>>Month

<<Entity>>Day

<<Control>>ChangeDate

<<Boundary>>Button

<<Boundary>>LCDDisplay

Entity Objects Control Objects Boundary Objects

Page 24: Chapter 5: Analysis Part I: Object Modeling Part II: Dynamic Modeling Qutaibah Malluhi Software Engineering Qatar University Based on slides by Bernd

Naming Conventions to Distinguish Object Types Can distinguish the different object types on a syntactical

basis. E.g., can use suffixes: Objects ending with the “_Boundary” suffix are boundary objects Objects ending with the “_Control” suffix are control objects Entity objects do not have any suffix appended to their name

Year

Month

Day

ChangeDate_Control

Button_Boundary

LCDDisplay_Boundary

Page 25: Chapter 5: Analysis Part I: Object Modeling Part II: Dynamic Modeling Qutaibah Malluhi Software Engineering Qatar University Based on slides by Bernd

Example: Flow of events

The customer enters a store with the intention of buying a toy for his child with the age of n.

Help must be available within less than one minute.

The store owner gives advice to the customer. The advice depends on the age range of the child and the attributes of the toy.

The customer selects a dangerous toy which is kind of unsuitable for the child.

The store owner recommends a more yellow doll.

Page 26: Chapter 5: Analysis Part I: Object Modeling Part II: Dynamic Modeling Qutaibah Malluhi Software Engineering Qatar University Based on slides by Bernd

Mapping parts of speech to object model components [Abbott, 1983]

Part of speech Model component Example

Proper noun object Jim Smith

Improper noun class Toy, doll

Doing verb method Buy, recommend

Being verb inheritance is-a (kind-of)

Having verb aggregation has an

Modal verb constraint must be

Adjective attribute 3 years old

Transitive verb method enter

Intransitive verb method (event) depends on

Page 27: Chapter 5: Analysis Part I: Object Modeling Part II: Dynamic Modeling Qutaibah Malluhi Software Engineering Qatar University Based on slides by Bernd

Abbot’s Analysis Example The customer enters the store to buy

a toy. It has to be a toy that his daughter

likes and it must cost less than $50. He tries a videogame, which uses a

data glove and a head-mounted display. He likes it.

An assistant helps him. The suitability of the game depends on the age of the child. His daughter is only 3 years old. The assistant recommends another type of toy, namely the board game "Monopoly".

Flow of events:

Is this a good useCase?

“Monopoly” is probably a left over from the scenario3 years old also indicates

Scenario rather than use case

The use case should terminate with the

customer leaving the store

Not quite!

Page 28: Chapter 5: Analysis Part I: Object Modeling Part II: Dynamic Modeling Qutaibah Malluhi Software Engineering Qatar University Based on slides by Bernd

Grammatical construct UML Component

Concrete Person, Thing Object

Noun class

Verb Operation

Classifying verb Inheritance

Having Verb Aggregation

Modal Verb Constraint

Adjective Attribute

Intransitive verb Operation (Event)

Textual Analysis using Abbot‘s technique

Example

“Monopoly"

“toy"

“enters"

“is a" ,“either .. or", “kind of…"

"Has a ", “consists of"

“must be", “less than…"

"3 years old"

“depends on…."

Page 29: Chapter 5: Analysis Part I: Object Modeling Part II: Dynamic Modeling Qutaibah Malluhi Software Engineering Qatar University Based on slides by Bernd

The customer enters the store to buy a toy. It has to be a toy that his daughter likes and it must cost less than $50. He tries a videogame, which uses a data glove and a head-mounted display. He likes it.

Class diagram from flow of events

An assistant helps him. The suitability of the game depends on the age of the child. His daughter is only 3 years old. The assistant recommends another type of toy, namely a board game. The customer buy the game and leaves the store

type of toy

customer

depends

storeentersCustomer

?

enter()

toy

daughter

suitable

*

less than $50store

enter()

daughterage

toy

buy()

videogame boardgame

toy

age

videogame

daughter

board game

Flow of events:

toypricebuy()like()

buy

likes

Page 30: Chapter 5: Analysis Part I: Object Modeling Part II: Dynamic Modeling Qutaibah Malluhi Software Engineering Qatar University Based on slides by Bernd

Example: Identify Classes

Title: Search for Supplier InformationPreconditions: Dental Office System has been initializedPost-conditions: If the search is successful, then the supplier information

is displayed. If the search is not successful, then an error message is displayed.

Normal Flow: The Operator requests to search for supplier. The Operator may

perform a keyword search using the Boolean operators “not”, “and”, and “or”. The Operator may enter up to three keywords

The system displays the name, phone number, fax number, and address of the suppliers that match the search criteria.

Alternate Flow The Operator requests to search for supplier. The Operator may

perform a keyword search using the Boolean operators “not”, “and”, and “or”.

If no matches are found, then the system displays an error message to the Operator.

Page 31: Chapter 5: Analysis Part I: Object Modeling Part II: Dynamic Modeling Qutaibah Malluhi Software Engineering Qatar University Based on slides by Bernd

Example: Identify Classes

Title: Search for Supplier InformationPreconditions: Dental Office System has been initializedPost-conditions: If the search is successful, then the supplier information

is displayed. If the search is not successful, then an error message is displayed.

Normal Flow: The Operator requests to search for supplier. The Operator may

perform a keyword search using the boolean operators “not”, “and”, and “or”. The Operator may enter up to three keywords.

The system displays the name, phone number, fax number, and address of the suppliers that match the search criteria to the Operator.

Alternate Flow The Operator requests to search for supplier. The Operator may

perform a keyword search using the boolean operators “not”, “and”, and “or”.

If no matches are found, then the system displays an error message to the Operator.

Page 32: Chapter 5: Analysis Part I: Object Modeling Part II: Dynamic Modeling Qutaibah Malluhi Software Engineering Qatar University Based on slides by Bernd

Order of activities in modeling

Formulate a few scenarios with help from the end user and/or application domain expert.

Extract the use cases from the scenarios, with the help of application domain expert.

Analyze the flow of events, for example with Abbot's textual analysis. Generate the class diagrams, which includes the following steps:

Class identification (textual analysis, domain experts). Identification of attributes and operations (sometimes before the classes

are found!) Identification of associations between classes Identification of multiplicities Identification of roles (label associations)

Page 33: Chapter 5: Analysis Part I: Object Modeling Part II: Dynamic Modeling Qutaibah Malluhi Software Engineering Qatar University Based on slides by Bernd

Object Modeling in Practice: Class Identification

Foo

RoutingNo

CustomerId

Deposit()Withdraw()GetBalance()

Class Identification: Name of Class, Attributes and Methods

Page 34: Chapter 5: Analysis Part I: Object Modeling Part II: Dynamic Modeling Qutaibah Malluhi Software Engineering Qatar University Based on slides by Bernd

Object Modeling in Practice: Encourage Brainstorming

Foo

Balance

CustomerId

Deposit()Withdraw()GetBalance()

Account

Balance

CustomerId

Deposit()Withdraw()GetBalance()

Naming is important! Is Foo the right name?

“Dada”

Balance

CustomerId

Deposit()Withdraw()GetBalance()

Page 35: Chapter 5: Analysis Part I: Object Modeling Part II: Dynamic Modeling Qutaibah Malluhi Software Engineering Qatar University Based on slides by Bernd

Object Modeling in Practice ctd

Account

Balance

Deposit()Withdraw()GetBalance()

Customer

NameCustomerId

1) Find New Objects

CustomerIdAccountId

2) Iterate on Names, Attributes and Methods

Bank

Name

Page 36: Chapter 5: Analysis Part I: Object Modeling Part II: Dynamic Modeling Qutaibah Malluhi Software Engineering Qatar University Based on slides by Bernd

Object Modeling in Practice: A Banking System

Account

Betrag

Deposit()Withdraw()GetBalance()

Customer

NameCustomerId

CustomerIdAccountId

AccountIdBank

Name

1) Find New Objects

2) Iterate on Names, Attributes and Methods

3) Find Associations between Objects

Has

4) Label the associations5) Determine the multiplicity of the associations

*

Page 37: Chapter 5: Analysis Part I: Object Modeling Part II: Dynamic Modeling Qutaibah Malluhi Software Engineering Qatar University Based on slides by Bernd

Practice Object Modeling: Iterate, Categorize!

Customer

Name

CustomerId()

Account

Balance

Deposit()Withdraw()GetBalance()

CustomerIdAccountId

AccountId

Bank

Name Has**

SavingsAccount

Withdraw()

CheckingAccount

Withdraw()

MortgageAccount

Withdraw()

Page 38: Chapter 5: Analysis Part I: Object Modeling Part II: Dynamic Modeling Qutaibah Malluhi Software Engineering Qatar University Based on slides by Bernd

Improving Readability of Class Diagrams

NamingRepresentative namesNaming conventions

Don’t put too many classes into the same package or page7+-2 (or even 5+-2)

Put Taxonomies (inheritance relationships) on a separate diagram

Page 39: Chapter 5: Analysis Part I: Object Modeling Part II: Dynamic Modeling Qutaibah Malluhi Software Engineering Qatar University Based on slides by Bernd

Summary

System modeling Object model Dynamic model Functional model

Object modeling is the central activity Class identification is a major activity of object modeling There are some easy syntactic rules to find classes/objects

Page 40: Chapter 5: Analysis Part I: Object Modeling Part II: Dynamic Modeling Qutaibah Malluhi Software Engineering Qatar University Based on slides by Bernd

Dynamic Modeling

Page 41: Chapter 5: Analysis Part I: Object Modeling Part II: Dynamic Modeling Qutaibah Malluhi Software Engineering Qatar University Based on slides by Bernd

Outline of the Lecture

Dynamic modelingSequence diagramsState diagrams

Analysis example

Page 42: Chapter 5: Analysis Part I: Object Modeling Part II: Dynamic Modeling Qutaibah Malluhi Software Engineering Qatar University Based on slides by Bernd

Dynamic Modeling Diagrams

Diagrams for dynamic modeling Interaction diagrams describe the dynamic behavior between

objects Statecharts describe the dynamic behavior of a single object

Interaction diagrams Sequence Diagram:

Dynamic behavior of a set of objects arranged in time sequence. Models the system from a single use case point of view Good for real-time specifications and complex scenarios

Statechart Diagram: A state machine that describes the response of an object of a given

class to the receipt of outside stimuli (Events).

Page 43: Chapter 5: Analysis Part I: Object Modeling Part II: Dynamic Modeling Qutaibah Malluhi Software Engineering Qatar University Based on slides by Bernd

How do you find classes?

We have already established the following sources Application domain analysis: Talk to client to identify abstractions Application of general world knowledge and intuition Scenarios

Natural language formulation of a concrete usage of the system Use Cases

Natural language formulation of the functions of the system Textual analysis of problem statement (Abbott)

Now we show how identify classes from dynamic models Actions and activities in statechart diagrams are candidates for

public operations in classes Vertical activity lines in sequence diagrams are also candidates

for objects

Page 44: Chapter 5: Analysis Part I: Object Modeling Part II: Dynamic Modeling Qutaibah Malluhi Software Engineering Qatar University Based on slides by Bernd

Find Methods with Dynamic Modeling

Purpose: Detect and supply methods for the object model

How do we do this? Start with use case or scenario Model interaction between objects

sequence diagram

Model dynamic behavior of a single object statechart diagram

Page 45: Chapter 5: Analysis Part I: Object Modeling Part II: Dynamic Modeling Qutaibah Malluhi Software Engineering Qatar University Based on slides by Bernd

Sequence Diagram

From the flow of events in the use case or scenario proceed to the sequence diagram

Relation to object identification: Objects/classes have already been identified during

object modeling Objects are identified as a result of dynamic modeling

Heuristic: A event (message) always has a sender and a

receiver. Find them for each event => These are the objects

participating in the use case

Page 46: Chapter 5: Analysis Part I: Object Modeling Part II: Dynamic Modeling Qutaibah Malluhi Software Engineering Qatar University Based on slides by Bernd

FieldOfficer Report

EmergencyButton ReportEmergencyControl ReportEmergency

Form Emergency

Report Manage

EmergencyControl

press()

create()create()

submit()

fillContents()

submitReport()create()

submitReportToDispatcher()

Sequence Diagram for ReportEmergency Use Case

Page 47: Chapter 5: Analysis Part I: Object Modeling Part II: Dynamic Modeling Qutaibah Malluhi Software Engineering Qatar University Based on slides by Bernd

ManageEmergencyControl

IncidentForm Incident Acknowledgment Dispatcher

create()

createIncident()

create()

submit()

create()

submitReportToDispatcher() view()

Boundary

Page 48: Chapter 5: Analysis Part I: Object Modeling Part II: Dynamic Modeling Qutaibah Malluhi Software Engineering Qatar University Based on slides by Bernd

Sequence diagram for the ReportEmergency use case

(acknowledgment on the FieldOfficerStation).

FieldOfficer ReportEmergency

Control Acknowledgment

Notice Manage

EmergencyControl

create

view

acknowledgeReport()

Page 49: Chapter 5: Analysis Part I: Object Modeling Part II: Dynamic Modeling Qutaibah Malluhi Software Engineering Qatar University Based on slides by Bernd

Heuristics for Sequence Diagrams Layout:

1st column: Should correspond to the actor who initiated the use case

2nd column: Should be a boundary object 3rd column: Should be the control object that manages the rest of

the use case Creation:

Control objects are created by (input) boundary objects at the initiation of a use case

Boundary objects (for output) are created by control objects Access:

Entity objects are accessed by control and boundary objects, Entity objects should never call boundary or control objects: This

makes it easier to share entity objects across use cases and makes entity objects resilient against technology-induced changes in boundary objects.

Page 50: Chapter 5: Analysis Part I: Object Modeling Part II: Dynamic Modeling Qutaibah Malluhi Software Engineering Qatar University Based on slides by Bernd

Sequence Diagram Impact on Object Model Help identify new classes The Sequence Diagram also supplies us with a

lot of (new) events/messages For each object that receives an event there is a public

operation in the associated class The name of the operation is usually the name of the event. Help distribute behavior on objects

Page 51: Chapter 5: Analysis Part I: Object Modeling Part II: Dynamic Modeling Qutaibah Malluhi Software Engineering Qatar University Based on slides by Bernd

What else can we get out of sequence diagrams? Sequence diagrams are derived from use cases

See/inspect the internal structure of the use cases.

Determine how decentralized the system is. We distinguish two structures for sequence diagrams:

Fork diagrams Stair diagrams

Page 52: Chapter 5: Analysis Part I: Object Modeling Part II: Dynamic Modeling Qutaibah Malluhi Software Engineering Qatar University Based on slides by Bernd

Fork Diagram Much of the dynamic behavior is placed in a single object, usually the

control object. It knows all the other objects and often uses them for direct questions and commands.

Page 53: Chapter 5: Analysis Part I: Object Modeling Part II: Dynamic Modeling Qutaibah Malluhi Software Engineering Qatar University Based on slides by Bernd

Stair Diagram The dynamic behavior is distributed. Each object delegates some

responsibility to other objects. Each object knows only a few of the other objects and knows which objects can help with a specific behavior.

Page 54: Chapter 5: Analysis Part I: Object Modeling Part II: Dynamic Modeling Qutaibah Malluhi Software Engineering Qatar University Based on slides by Bernd

Fork or Stair?

Which of these diagram types should be chosen? Generally, stair structure is better

The more the responsibility is spread out, the better

However, this is not always true: Decentralized control structure

The operations have a strong connection always be performed in the same order

Centralized control structure (better support of change) The operations can change order New operations can be inserted as a result of new requirements

Page 55: Chapter 5: Analysis Part I: Object Modeling Part II: Dynamic Modeling Qutaibah Malluhi Software Engineering Qatar University Based on slides by Bernd

Statechart Diagrams Graph whose nodes are states and whose directed arcs are

transitions labeled by event names. We distinguish between two types of operations in statecharts:

Activity: Operation that takes time to complete associated with states

Action: Instantaneous operation associated with events associated with states (reduces drawing complexity): Entry, Exit, Internal

Action

A statechart diagram relates events and states for one class An object model with a set of objects has a set of state diagrams

Page 56: Chapter 5: Analysis Part I: Object Modeling Part II: Dynamic Modeling Qutaibah Malluhi Software Engineering Qatar University Based on slides by Bernd

UML Statechart Diagram Notation

State2State1 Event1(attr) [condition]/action

entry /action

exit/action

do/Activity

Also: internal actions

Event triggerWith parameters

Guardcondition

Page 57: Chapter 5: Analysis Part I: Object Modeling Part II: Dynamic Modeling Qutaibah Malluhi Software Engineering Qatar University Based on slides by Bernd

Vending Machine StateChart Diagram

do: test item and compute change

do: make changedo: dispense item

Idle

[item empty] [select(item)]

[change=0] [change>0]

[change<0]

Collect Moneycoins_in(amount) / add to balance

coins_in(amount) / set balance

cancel / refund coins

Page 58: Chapter 5: Analysis Part I: Object Modeling Part II: Dynamic Modeling Qutaibah Malluhi Software Engineering Qatar University Based on slides by Bernd

Nested State Diagram

Activities in states are composite items denoting other lower-level state diagrams

A lower-level state diagram corresponds to a sequence of lower-level states and events that are invisible in the higher-level diagram.

Sets of substates in a nested state diagram denote a superstate are enclosed by a large rounded box.

Page 59: Chapter 5: Analysis Part I: Object Modeling Part II: Dynamic Modeling Qutaibah Malluhi Software Engineering Qatar University Based on slides by Bernd

Nested Statechart for Incident.

Active

Inactive Closed Archived

all

when date > 1yr.

resourcessubmitted reports

Reported Assessment

DisengagementResponse

field officerarrives on site

field officerreleases resources

dispatcherallocates resources

field officer requestsadditional resources

all resourcesdeallocated

Page 60: Chapter 5: Analysis Part I: Object Modeling Part II: Dynamic Modeling Qutaibah Malluhi Software Engineering Qatar University Based on slides by Bernd

State Chart Diagram vs Sequence Diagram State chart diagrams help to identify:

Changes to an individual object over time

Sequence diagrams help to identifyThe temporal relationship of between objects

over timeSequence of operations as a response to one

ore more events

Page 61: Chapter 5: Analysis Part I: Object Modeling Part II: Dynamic Modeling Qutaibah Malluhi Software Engineering Qatar University Based on slides by Bernd

1. What are the transformations? Create scenarios and use case diagrams

Talk to client, observe, get historical records, do thought experiments

2. What is the structure of the system?Create class diagrams

Identify objects. What are the associations between them? What is their multiplicity?What are the attributes of the objects?What operations are defined on the objects?

3. What is its behavior? Create sequence diagrams

Identify senders and receiversShow sequence of events exchanged between objects. Identify event dependencies and event concurrency.

Create state diagrams Only for the dynamically interesting objects.

Summary: Requirements Analysis

Dynamic Modeling

Functional Modeling

Object Modeling

Page 62: Chapter 5: Analysis Part I: Object Modeling Part II: Dynamic Modeling Qutaibah Malluhi Software Engineering Qatar University Based on slides by Bernd

Let’s Do Analysis

1. Analyze the problem statement Identify functional requirements Identify nonfunctional requirements Identify constraints (pseudo requirements)

2. Build the functional model: Develop use cases to illustrate functionality requirements

3. Build the dynamic model: Develop sequence diagrams to illustrate the interaction between

objects Develop state diagrams for objects with interesting behavior

4. Build the object model: Develop class diagrams showing the structure of the system

Page 63: Chapter 5: Analysis Part I: Object Modeling Part II: Dynamic Modeling Qutaibah Malluhi Software Engineering Qatar University Based on slides by Bernd

Problem Statement: Direction Control for a Toy Car Power is turned on

Car moves forward and car headlight shines

Power is turned off Car stops and headlight

goes out.

Power is turned on Headlight shines

Power is turned off Headlight goes out.

Power is turned on Car runs backward with its

headlight shining.

Power is turned on Car moves forward and car

headlight shines

Power is turned off Car stops and headlight

goes out.

Power is turned on Headlight shines

Power is turned off Headlight goes out.

Power is turned on Car runs backward with its

headlight shining.

Power is turned off Car stops and headlight

goes out. Power is turned on

Headlight shines Power is turned off

Headlight goes out. Power is turned on

Car runs forward with its headlight shining.

Power is turned off Car stops and headlight

goes out. Power is turned on

Headlight shines Power is turned off

Headlight goes out. Power is turned on

Car runs forward with its headlight shining.

Page 64: Chapter 5: Analysis Part I: Object Modeling Part II: Dynamic Modeling Qutaibah Malluhi Software Engineering Qatar University Based on slides by Bernd

Find the Functional Model: Do Use Case Modeling

Use case 1: System Initialization Entry condition: Power is off, car is not moving Flow of events:

Driver turns power on Exit condition: Car moves forward, headlight is on

Use case 2: Turn headlight off Entry condition: Car moves forward with headlights on Flow of events:

Driver turns power off, car stops and headlight goes out. Driver turns power on, headlight shines and car does not move. Driver turns power off, headlight goes out

Exit condition: Car does not move, headlight is out

Page 65: Chapter 5: Analysis Part I: Object Modeling Part II: Dynamic Modeling Qutaibah Malluhi Software Engineering Qatar University Based on slides by Bernd

Use Cases continued Use case 3: Move car backward

Entry condition: Car is stationary, headlights off Flow of events:

Driver turns power on Exit condition: Car moves backward, headlight on

Use case 4: Stop backward moving car Entry condition: Car moves backward, headlights on Flow of events:

Driver turns power off, car stops, headlight goes out. Power is turned on, headlight shines and car does not move. Power is turned off, headlight goes out.

Exit condition: Car does not move, headlight is out. Use case 5: Move car forward

Entry condition: Car does not move, headlight is out Flow of events

Driver turns power on Exit condition:

Car runs forward with its headlight shining.

Page 66: Chapter 5: Analysis Part I: Object Modeling Part II: Dynamic Modeling Qutaibah Malluhi Software Engineering Qatar University Based on slides by Bernd

Use Case Pruning

Do we need use case 5?

Use case 1: System Initialization Entry condition: Power is off, car is not moving Flow of events:

Driver turns power on Exit condition: Car moves forward, headlight is on

Use case 5: Move car forward Entry condition: Car does not move, headlight is out Flow of events

Driver turns power on Exit condition:

Car runs forward with its headlight shining.

Page 67: Chapter 5: Analysis Part I: Object Modeling Part II: Dynamic Modeling Qutaibah Malluhi Software Engineering Qatar University Based on slides by Bernd

Find the Dynamic Model: Create sequence diagram Name: Drive Car Sequence of events:

Billy turns power onHeadlight goes onWheels starts moving forwardWheels keeps moving forwardBilly turns power offHeadlight goes offWheels stops moving . . .

Page 68: Chapter 5: Analysis Part I: Object Modeling Part II: Dynamic Modeling Qutaibah Malluhi Software Engineering Qatar University Based on slides by Bernd

Sequence Diagram for Drive Car Scenario

:Headlight Billy:Driver :Wheel

Power(on) Power(on)

Power(off) Power(off)

Power(on) Power(on)

Page 69: Chapter 5: Analysis Part I: Object Modeling Part II: Dynamic Modeling Qutaibah Malluhi Software Engineering Qatar University Based on slides by Bernd

Toy Car: Dynamic ModelWheel

Forward

Backward

Stationary Stationary

poweron

poweroff

poweroff

poweron

Headlight

poweron

poweroff

Off

On

Page 70: Chapter 5: Analysis Part I: Object Modeling Part II: Dynamic Modeling Qutaibah Malluhi Software Engineering Qatar University Based on slides by Bernd

Toy Car: Object Model

Wheel

Motion: (Forward,

Stationary) Backward,

Start_Moving()Stop_Moving()

Headlight

Status: (On, Off)

Switch_On()Switch_Off()

Power

Status: (On, Off)

TurnOn()TurnOff()

Car