Transcript CaseStudy_5

Optional Case Study - Chapter 5
Outline
5.1 Introduction
5.2 Collaborations
5.3 Creating Collaborations
5.4 Collaboration Diagrams
5.5 Summary
 2000 Deitel & Associates, Inc. All rights reserved.
5.1 Introduction
• This chapter
– Last OOD assignment before we begin study of OOP in Chapter 6
– Focus on object collaboration
• End of section
– List of Internet and WWW UML resources (look in text)
– Bibliography of UML resources (look in text)
• Chapter 6
– Begin coding simulator
• Chapters 7, 9
– Required to complete simulator
 2000 Deitel & Associates, Inc. All rights reserved.
5.2 Collaborations
• Collaboration - interaction between objects
1. Object of one class
2. Sends message
3. Received by object of another class
– Message invokes operation of second class
– In Chapter 4, we determined many operations
• Now, we focus on the messages that invoke them
• Next slide
– List of verb phrases that correspond to operations
• Some phrases removed from complete list of all verbs
– Remaining phrases are collaborations
 2000 Deitel & Associates, Inc. All rights reserved.
5.2 Collaborations (II)
Cla ss
Verb p hra ses
Elevator
resets the elevator button, sounds the elevator bell, signals its
arrival to a floor, opens its door, closes its door
Clock
Scheduler
ticks every second
tells a person to step onto a floor, verifies that a floor is
unoccupied
Person
presses floor button, presses elevator button, enters elevator,
exits elevator
Floor
resets floor button, turns off light, turns on light
FloorButton
summons elevator
ElevatorButton signals elevator to prepare to leave
Door
(opening of door) signals person to exit elevator, (opening of
door) signals person to enter elevator
Bell
Light
Building
increments the time, gets the time, provides the time to the
scheduler, provides the time to the elevator
 2000 Deitel & Associates, Inc. All rights reserved.
5.3 Creating Collaborations
• Creating Collaborations
– Examine list of verbs
– "resets elevator button" in class Elevator
– To do this:
• Elevator object sends resetButton message to
ElevatorButton object
• This invokes resetButton operation
• Next slide
– List of all collaborations that can be taken from our table of verb
phrases
 2000 Deitel & Associates, Inc. All rights reserved.
5.3 Creating Collaborations (II)
An o b jec t o f c la ss
Send s the m essa g e
To a n o b jec t o f c la ss
Elevator
resetButton
ringBell
elevatorArrived
openDoor
closeDoor
ElevatorButton
Bell
Floor
Door
Door
Scheduler
stepOntoFloor
isOccupied
Person
pressButton
pressButton
passengerEnters
passengerExits
personArrives
Floor
resetButton
turnOff
turnOn
Person
Floor
FloorButton
ElevatorButton
Elevator
Elevator
Floor
FloorButton
Light
Light
FloorButton
summonElevator
Elevator
ElevatorButton
prepareToLeave
Door
exitElevator
enterElevator
Elevator
Person
Person
tick
getTime
processTime
processTime
Clock
Clock
Scheduler
Elevator
Clock
Bell
Light
Building
 2000 Deitel & Associates, Inc. All rights reserved.
5.4 Collaboration Diagrams
• Collaboration diagrams
– Model interaction of objects
– Focus on which objects participate in interactions
– Sequence diagrams focus on when interactions occur
• Format
– Rectangle - represents object, has name inside
– Solid lines - connect collaborating objects
• Message passed along direction shown by arrows
• Name of message by arrow
– Sequence of messages - numerical ordering of messages
 2000 Deitel & Associates, Inc. All rights reserved.
4.2:
Door
sends
message to waitingperson
3: Elevator
4: Elevator
notifies
opensfloor
doorofenterElevator
arrival
5.4
Collaboration
Diagrams
4.1:
Door
4.2.1
sends
passengerEnters
exitElevator
message
to
passenger
3.1:
Floor
resets
its
button
1: Elevator resets button
passengerExits
3.2:4.1.1
Floor
(This
turns
sequence
on its light
ensures that a person exits before another enters)
2: Elevator
rings
bell
: FloorButton
: Light
3.1: resetButton( )
3.2: turnOn( )
: Floor
3: elevatorArrived( )
4.2.1: passengerEnters( )
waitingPassenger : Person
4.1.1: passengerExits( )
: Elevator
passenger : Person
1: resetButton( )
2: ringBell( )
: Bell
: ElevatorButton
4: openDoor( )
4.2: enterElevator( )
4.1: exitElevator( )
: Door
 2000 Deitel & Associates, Inc. All rights reserved.
5.5 Summary
• Reasonably complete listing of classes
– Chapter 6 - implement large portion of simulator
– Chapter 7 - implement complete, working simulator
– Chapter 9 - discuss inheritance
• Summary of object-oriented design process
0. Analysis phase - meet with clients, gather information
• Create use cases to describe how users interact with system
• In this example, began with problem statement (no analysis phase)
1. Classes - locate classes by listing nouns in problem statement
• Eliminate nouns that are attributes of classes, and nouns that are not
part of the system
• Create a diagram that models classes and associations
 2000 Deitel & Associates, Inc. All rights reserved.
5.5 Summary
• Summary of OOD process (continued)
2. Attributes - extract attributes by listing words that describe classes
3. Dynamic Nature - create statechart diagrams to learn how classes
change over time
4. Operations - examine verbs associated with each class
• Extract operations
• Use activity diagrams to model details of operations
5. Collaborations - examine interactions between objects
• Use sequence and collaboration diagrams
• Add attributes and operations as needed
• Design
– We are probably missing a few pieces
– This will become apparent as we implement the simulator in
Chapter 6
 2000 Deitel & Associates, Inc. All rights reserved.