Object Modeling

Conquering Complex and Changing Systems
Object-Oriented Software Engineering
Chapter 5, Analysis:
Object Modeling
Outline

From use cases to objects

Object modeling

Class vs. instance diagrams

Attributes

Operations & methods

Links & associations

Examples of associations

Two special associations
 Aggregation
 Inheritance
Bernd Bruegge & Allen Dutoit
Object-Oriented Software Engineering: Conquering Complex and Changing Systems
2
Requirements Elicitation & Analysis
Requirements
Elicitation
Bernd Bruegge & Allen Dutoit
System
Specification
Analysis
Analysis
Model
System
Design
System
Model
Object-Oriented Software Engineering: Conquering Complex and Changing Systems
3
Analysis Model
Use Case
Diagram:View
Class
Diagram:View
Functional:
Model
Object:
Model
Statechart
Diagram:View
Sequence
Diagram:View
Dynamic:
Model
Object:
Model
Bernd Bruegge & Allen Dutoit
Object-Oriented Software Engineering: Conquering Complex and Changing Systems
4
Why Functional Decomposition is not Enough
Scenarios
Level 1
Level 2
Level 3
A
Level 3
Level 3
Level 4
Level 1 Use Cases
Level 2
Level 2 Use Cases
Operations
Level 4
B
Participating
Objects
Bernd Bruegge & Allen Dutoit
Object-Oriented Software Engineering: Conquering Complex and Changing Systems
5
How do we describe complex systems?
(Natural Systems, Social Systems, Artificial Systems)
Knowledge
Describes our knowledge about the system
Knowledge about Causality
(Dynamic Model)
State Diagrams
(Harel)
Sequence
Diagrams
Activity
Diagrams
Petri Nets(Petri)
Uncertain Knowledge
Fuzzy Sets (Zadeh)
Fuzzy Frames
(Graham)
Bernd Bruegge & Allen Dutoit
Knowledge about Relationships
(Object model)
Knowledge about Functionality
(Functional model)
Formal
Specifications
(Liskov)
Neural
Networks
DataFlow Diagrams
(SA/SD)
Scenarios/Use Cases
Data Relationship (Jacobsen)
Inheritance
Frames,SemanticNet (E/R Modeling, Chen)
works (Minsky)
Class Diagrams
(“E/R + Inheritance”,
Rumbaugh)
Hierarchical
Database
Model (IMS)
Network
Relational
Database
Database Model
Model
(Codd)
(CODASYL)
Object-Oriented Software Engineering: Conquering Complex and Changing Systems
6
Definition: Object Modeling

Goal: Find the important abstractions

What happens if we find the wrong abstractions?
 Iterate until correct!

Steps: Identify
 1. Classes
 2. Methods
 3. Attributes
 4. Associations between classes

Order of steps
 Goal: get the desired abstractions
 Order of steps secondary, only a heuristic
 Iteration is important
Bernd Bruegge & Allen Dutoit
Object-Oriented Software Engineering: Conquering Complex and Changing Systems
7
Links & Associations

Link[association] establishes relationships among
objects[classes].

Link: an instance of an association

Association
 A bidirectional mapping.
 1-to-1, many-to-1, 1-to-many,
 An association describes a set of links like
a class describes a set of objects.
Bernd Bruegge & Allen Dutoit
Object-Oriented Software Engineering: Conquering Complex and Changing Systems
8
1-to-1 & 1-to-many Associations
Country
City
Has-capital
name:String
name:String
1-to-1 association
StickyNote
Workorder
*
schedule()
x: Integer
y: Integer
z: Integer
1-to-many association
Bernd Bruegge & Allen Dutoit
Object-Oriented Software Engineering: Conquering Complex and Changing Systems
9
Many-to-Many Associations
Mechanics
Bernd Bruegge & Allen Dutoit
*
Work on
*
Plane
Object-Oriented Software Engineering: Conquering Complex and Changing Systems
10
Do UML associations have direction?
 A association between 2 classes is by default a bi-directional
mapping.
B
A


Class A can access class B & class B can access class A
Both classes play the agent role.
To make A
a client,
& B a server, make the association
Name
of association
Name Direction
unidirectional.
The arrowhead points to the server
A
accesses
B
Association Direction
Class A ( the “client”) accesses class B (“the server”).
B is also called navigable
Bernd Bruegge & Allen Dutoit
Object-Oriented Software Engineering: Conquering Complex and Changing Systems
11
Aggregation



Models "part of" hierarchy
Models the breakdown of a product into its components
An association with a diamond indicating the assembly end of
the relation.
Bernd Bruegge & Allen Dutoit
Object-Oriented Software Engineering: Conquering Complex and Changing Systems
12
Aggregation
Automobile
Engine
serial number
year
manufacturer
model
color
weight
horsepower
volume
on
off
drive
purchase
3,4,5
Wheel
diameter
number of bolts
Bernd Bruegge & Allen Dutoit
*
Brakelight
on
off
2,4
Door
open
close
Battery
amps
volts
charge
discharge
Object-Oriented Software Engineering: Conquering Complex and Changing Systems
13
Inheritance



Models "kind of" hierarchy
Models commonalities among classes, preserving differences
An arrow with a triangle
Cell
BloodCell
Red
Bernd Bruegge & Allen Dutoit
White
MuscleCell
Smooth
Striate
NerveCell
Cortical
Object-Oriented Software Engineering: Conquering Complex and Changing Systems
Pyramidal
14
Object Types

Model objects
 Represent the application domain being modeled


E.g., a region of the complex plane
View objects
 Represent a view of the application domain


The 2D colorized view of the region of the complex plane
Control objects
 Represent parameters that control either the model itself or the
view.

The Model/View/Controller (MVC) is a design pattern that
relates but decouples these kinds of objects.
 Makes it easy to change 1 aspect w/o affecting the others.
Bernd Bruegge & Allen Dutoit
Object-Oriented Software Engineering: Conquering Complex and Changing Systems
15
Example: 2BWatch Objects


UML has several language extension mechanisms
UML provides the stereotype mechanism to present new modeling elements
<<entity>>
Year
<<entity>>
Month
<<control>>
ChangeDateControl
<<boundary>>
ButtonBoundary
<<boundary>>
LCDDisplayBoundary
<<entity>>
Day
Bernd Bruegge & Allen Dutoit
Object-Oriented Software Engineering: Conquering Complex and Changing Systems
16
Roles

A role is a name that uniquely identifies 1 end of an association.

A role appears next to the the class that plays the role.

When do you use role names?
 For associations between 2 objects of the same class
 To distinguish between 2 associations between the same pair of classes
Bernd Bruegge & Allen Dutoit
Object-Oriented Software Engineering: Conquering Complex and Changing Systems
17
Example of Role
Problem Statement : A person assumes the role of repairperson
with respect to another person, who assumes the role of inspector
Person
Person
*
Person
Bernd Bruegge & Allen Dutoit
Creates Workorders
inspector
Creates Workorders
*
repairperson
Person
Object-Oriented Software Engineering: Conquering Complex and Changing Systems
18
Roles in Associations

Client Role
 An object that operates on other objects but is never operated on by
other objects.

Server Role
 An object that never operates on other objects. It only is operated
on by other objects.

Agent Role
 An object that operates on other objects & is operated on by other
objects.
 An agent is usually works on behalf of an actor or another agent.
Bernd Bruegge & Allen Dutoit
Object-Oriented Software Engineering: Conquering Complex and Changing Systems
19
How do you find classes?

Learn about problem domain: Observe your client

Find participating objects in use cases’ flow of events

Apply design patterns (E.g., discover MVC relationships)

Establish a taxonomy (Inheritance relations)

Nouns are candidates for classes
Bernd Bruegge & Allen Dutoit
Object-Oriented Software Engineering: Conquering Complex and Changing Systems
20
Mapping Parts of Speech to Object Model Components
Part of speech
Model component
Proper noun
object
Example
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
red
Bernd Bruegge & Allen Dutoit
Object-Oriented Software Engineering: Conquering Complex and Changing Systems
21
Heuristics for Identifying Associations

Examine verb phrases.

Name associations & roles precisely.

Omit associations derivable from others
 Associations are transitive: Omit association cycles


FieldOfficer writes EmergencyReport

EmergencyReport triggers Incident

FieldOfficer reports Incident (Incident is reported by FieldOfficer)
After associations are stable, document multiplicities
Bernd Bruegge & Allen Dutoit
Object-Oriented Software Engineering: Conquering Complex and Changing Systems
22
Heuristics for Identifying Attributes

Examine possessive phrases.

Represent object’s state as attributes.

Describe each attribute.

Identify attributes only after class structure is stable.
Bernd Bruegge & Allen Dutoit
Object-Oriented Software Engineering: Conquering Complex and Changing Systems
23
Example: Scenario from Problem Statement

Jim Smith enters a store with the intention of buying a toy for his 3
year old child.

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.

Jim selects a dangerous toy which is unsuitable for the child.

The store owner recommends a more yellow doll.
Bernd Bruegge & Allen Dutoit
Object-Oriented Software Engineering: Conquering Complex and Changing Systems
24
Object Modeling in Practice: Class Identification
Foo
Balance
CustomerId
Deposit()
Withdraw()
GetBalance()
Class Identification: Name of Class, Attributes and Methods
Bernd Bruegge & Allen Dutoit
Object-Oriented Software Engineering: Conquering Complex and Changing Systems
25
Object Modeling in Practice:
Encourage Brainstorming
“Dada”
Foo
Balance
Balance
CustomerId
CustomerId
Deposit()
Withdraw()
GetBalance()
Deposit()
Withdraw()
GetBalance()
Account
Balance
CustomerId
Naming is important!
Bernd Bruegge & Allen Dutoit
Deposit()
Withdraw()
GetBalance()
Object-Oriented Software Engineering: Conquering Complex and Changing Systems
26
Object Modeling in Practice
Account
Bank
Name
Balance
AccountId
Deposit()
Withdraw()
GetBalance()
Customer
Name
CustomerId
Find New Objects
Iterate on Names, Attributes & Methods
Bernd Bruegge & Allen Dutoit
Object-Oriented Software Engineering: Conquering Complex and Changing Systems
27
Object Modeling in Practice: A Banking System
Account
Bank
Name
Balance
AccountId
Customer
*
Has
Deposit()
Withdraw()
GetBalance()
Name
CustomerId
Find Associations
Name the associations
Determine their multiplicities
Bernd Bruegge & Allen Dutoit
Object-Oriented Software Engineering: Conquering Complex and Changing Systems
28
Object Modeling in Practice: Categorize
Account
Bank
*
Name
Balance
AccountId
Customer
*
Has
Deposit()
Withdraw()
GetBalance()
Name
CustomerId
Savings
Account
Checking
Account
Mortgage
Account
Withdraw()
Withdraw()
Withdraw()
Bernd Bruegge & Allen Dutoit
Object-Oriented Software Engineering: Conquering Complex and Changing Systems
29
Object Modeling in Practice: Heuristics

Schedule team meetings to identify objects

Differentiate between model, view, & control objects

Find associations & their multiplicity
 Unusual multiplicities usually lead to new objects or categories

Identify Aggregation

Identify Inheritance: Look for a Taxonomy, Categorize

Allow time for brainstorming; iterate!
Bernd Bruegge & Allen Dutoit
Object-Oriented Software Engineering: Conquering Complex and Changing Systems
30
Development Roles
Assign individuals to the following roles:

User: application domain expert. May be many different users.

Client: Overall responsibility for system scope based on user
requirements.

Analyst: Details use case[s]; identify objects, associations,
attributes of the use case. May be many analysts.

Architect: Unifies use case model.

Document editor: Responsible for assembling the RAD.

Configuration manager: Maintains revision history.

Quality & Assurance: Validates the RAD for correctness,
completeness, consistency, realism, verifiability, & traceability.
Bernd Bruegge & Allen Dutoit
Object-Oriented Software Engineering: Conquering Complex and Changing Systems
31
A Revision Process
CLIENT
Report problem or
change request
DEVELOPER
Design change,
estimate impact
<!approved>
Review proposed
change
<approved>
Update RAD
Design
test
Review actual
change
Bernd Bruegge & Allen Dutoit
Update
design
Archive
request
Update
code
Unit test,
regression test
Object-Oriented Software Engineering: Conquering Complex and Changing Systems
32
Summary

Identify objects

Generalize concrete classes

Refine objects with attributes & operations

Identify associations
Bernd Bruegge & Allen Dutoit
Object-Oriented Software Engineering: Conquering Complex and Changing Systems
33