Behavioral Diagrams - Interaction Diagrams

Download Report

Transcript Behavioral Diagrams - Interaction Diagrams

Object-Oriented Analysis and Design
Behavioral Modeling with UML
Behavioral Diagrams
Interaction Diagrams
Week #4
Jarungjit Parnjai
Burapha University, 2001
Object-Oriented Analysis and Design
Lecture Outline
• UML Behavioral Diagrams
• Interaction Diagrams
• Sequence Diagram
• Collaboration Diagram
Burapha University, 2001
Object-Oriented Analysis and Design
UML has 9 kinds of diagrams









Class Diagram
Object Diagram
Component Diagram
Deployment Diagram
Use Case Diagram
Sequence Diagram
Collaboration Diagram
StateTransition Diagram
Activity Diagram
Structural Diagrams
Behavioral Diagrams
Burapha University, 2001
Object-Oriented Analysis and Design
UML(Unified Modeling Language)
• 5 มุมมองหลักของ UML
• Use-case view : หน้ าที่การทางานของระบบซอฟต์ แวร์ โดยพิจารณา
จากมุมมองของผู้ใช้ ภายนอก หรือ ระบบภายนอก
• use-case diagram
• Logical view : หน้ าที่การทางานของระบบมีโครงสร้ างอย่ างไร มองใน
รูปของ static structure และ dynamic behavior
• class diagram, object diagram, state, sequence, collaboration,
activity diagrams
Burapha University, 2001
Object-Oriented Analysis and Design
UML(Unified Modeling Language)
• Component view : องค์ ประกอบย่ อยในการ implement ที่ประกอบ
เป็ นระบบ และ dependency ระหว่ างองค์ ประกอบเหล่านั้น
• component diagram
• Concurrency view: การแบ่ งแยก process และ processors โดย
พิจารณาทั้ง communication และ synchronization
• dynamic diagrams (state, sequence, collaboration activity)
• implementation diagrams(component และ deployment)
• Deployment view : โครงสร้ างทางกายภาพเกีย่ วกับ การติดตั้ง และใช้
งานระบบ
• deployment diagram
Burapha University, 2001
Object-Oriented Analysis and Design
Static & Dynamic views
• ระบบใดๆ มักประกอบด้ วยโครงสร้ าง 2 แบบ ได้ แก่
• static และ dynamic
• โครงสร้ างของ Use Case และ Class Diagram เป็ นแบบ static
• แสดงองค์ ประกอบของระบบ คลาส แอททริบิวต์ เมทธอด
และ ความสั มพันธ์ ระหว่ างคลาส
• ไม่ ระบุข้นั ตอนการดาเนินงาน ลาดับการทางานก่ อนหลัง
• โครงสร้ างของ Behavioral Diagrams เป็ นแบบ dynamic
Burapha University, 2001
Object-Oriented Analysis and Design
Behavioral Diagrams
• Behavioral Diagrams เป็ นโครงสร้ างแบบ dynamic
• 4 diagrams ได้ แก่
• Sequence Diagram
Interaction Diagrams
• Collaboration Diagram
• State-transition Diagram
• Activity Diagram
Burapha University, 2001
Object-Oriented Analysis and Design
Interaction Diagrams
Burapha University, 2001
Object-Oriented Analysis and Design
Interaction diagrams
•
•
•
•
แสดงการปฏิสัมพันธ์ ระหว่ างกลุ่มของวัตถุ
มักใช้ อธิบายสถานการณ์ ของ use case 1 use case
อธิบายการติดต่ อสื่ อสารระหว่ างวัตถุ
2 รู ปแบบ
• Time-based (Sequence Diagram)
• Organization-based (Collaboration Diagram)
Burapha University, 2001
Object-Oriented Analysis and Design
Sequence & Collaboration Diagrams
• ทั้ง 2 diagrams แสดง message ทีถ่ ูกส่ งผ่ านระหว่ างวัตถุที่
ทางานร่ วมกัน เพือ่ ประกอบเป็ นหน้ าที่การทางานของระบบ
• Sequence diagrams เน้ น message ที่เกิดขึน้ ตามลาดับของ
เวลา
• Collaboration diagrams เน้ นการเชื่อมต่ อทางด้ าน
โครงสร้ างระหว่ างวัตถุทที่ างานร่ วมกัน
Burapha University, 2001
Object-Oriented Analysis and Design
Sequence & Collaboration Diagrams
• ทั้ง 2 diagrams สามารถใช้ ในการจาลองการปฏิสัมพันธ์
ระหว่ างวัตถุ กับระบบทั้งหมด
• หรือ อาจใช้ ในการจาลองปฏิสัมพันธ์ ที่เกีย่ วข้ องใน Use Case
ใด Use Case หนึ่งโดยเฉพาะ
Burapha University, 2001
Object-Oriented Analysis and Design
A Sequence Diagram
: Student
registration
form
registration
manager
math 101
section 1
math 101
1: fill in info
2: submit
3: add course(joe, math 01)
4: are you open?
5: are you open?
6: add (joe)
7: add (joe)
Burapha University, 2001
A Collaboration Diagram
Object-Oriented Analysis and Design
1: set course info
2: process
course form :
CourseForm
3: add course
: Registrar
theManager :
CurriculumManager
aCourse :
Course
4: new course
Burapha University, 2001
Object-Oriented Analysis and Design
Interactions : Core Elements
Construct
Description
Instance
(object,
data
value,
componen
t instance
etc.)
An entity with a unique identity and
to which a set of operations can be
applied (signals be sent) and which
has a state that stores the effects of
the operations (the signals).
Action
A specification of an executable
statement.
A few different kinds of actions are
predefined, e.g. CreateAction,
CallAction, DestroyAction, and
UninterpretedAction.
Syntax
name
attr values
textual
Burapha University, 2001
Object-Oriented Analysis and Design
Interaction : Core Elements (cont’d)
Construct
Description
Syntax
Stimulus
A communication between two
instances.
Operation
A declaration of a service that can
be requested from an instance to
effect behavior.
textual
Signal
A specification of an asynchronous
stimulus communicated between
instances.
«Signal»
Name
parameters
Burapha University, 2001
Object-Oriented Analysis and Design
Interaction: Core Relationships
Construct
Description
Link
A connection between instances.
Attribute Link
A named slot in an instance, which
holds the value of an attribute.
Return
A return from method call
Syntax
textual
Burapha University, 2001
Object-Oriented Analysis and Design
Sequence diagrams
• แสดงการปฏิสัมพันธ์ ระหว่ างวัตถุตามลาดับเวลา (time
sequence)
• ประกอบด้ วย
• actor หรือ object ทีม่ ีปฏิสัมพันธ์ กบั วัตถุอนื่ ๆ
• เส้ นชีวติ (lifeline)
• Message ที่ส่งผ่ านระหว่ าง Object หรือ actor
Burapha University, 2001
Object-Oriented Analysis and Design
Content of sequence diagrams
• Actor หรือ วัตถุ (Objects)
• แลกเปลีย่ น messages ให้ แก่กนั และกัน
• เส้ นชีวติ (Lifeline)
• แสดงว่ าวัตถุถูกสร้ างขึน้ และยังไม่ ถูกทาลาย
• Messages
• message ที่ส่งผ่ านระหว่ าง objects สนับสนุนการปฏิสัมพันธ์
ระหว่ างวัตถุ
• เป็ นวิธีการที่ object ใช้ ในการขอรับบริการจากวัตถุอนื่ ๆ
• object ใดๆ ติดต่ อสื่ อสารกับ object อืน่ ๆ ผ่ านทาง operation
ของวัตถุน้ันๆ
Burapha University, 2001
Object-Oriented Analysis and Design
• Simple
Message Types
• Sender / Receiver
• ไม่ ระบุรายละเอียดของวิธีการติดต่ อสื่ อสารระหว่ างวัตถุ
• Synchronous
• เรียกใช้ Operation ของวัตถุ โดย Sender/Caller รอจน สิ้นสุ ด
Operation
• Receiver จัดเป็ น passive object
• Asynchronous
• ไม่ มีการ return กลับไปยัง Sender/Caller
• Sender ทางานต่ อทันที่ทสี่ ่ ง message
• Receiver จัดเป็ น active object
Burapha University, 2001
Object-Oriented Analysis and Design
Message Notation
Simple
Synchronous
Asynchronous
(Message return)
Burapha University, 2001
Object-Oriented Analysis and Design
Notation : Sequence Diagram
object symbol
name : Class
lifeline
activation
other
stimulus
[condition]
name (…)
new (…)
message
: Class
delete
create
return
Burapha University, 2001
Object-Oriented Analysis and Design
Example: Different Arrows
Flat Flow
Nested Flow
telle
r
: Order
: Article
getValue
caller
exchange
Asynchronous Flow
callee
lift receiver
err handl alarm
unknown
alarm
dial tone
price
appl
dial digit
dial digit
getName
ringing tone
ringing
signal
lift
receiver
Burapha University, 2001
Object-Oriented Analysis and Design
Example: Sequence diagram
: Registrar
course form :
CourseForm
theManager :
CurriculumManager
Set Course Info
Object
creation
process
Add Course
<<create>>
aCourse :
Course
Burapha University, 2001
Object-Oriented Analysis and Design
Example: Sequence diagram
Actor
: Customer
: Computer
: Printer
Server
: Printer
: Queue
Print(file)
Print(file)
Message
[Printer free]
Print(file)
[Printer busy]
Print(file)
Lifeline
Burapha University, 2001
Object-Oriented Analysis and Design
Interaction & Collaboration Diagrams
Sequence Diagram
x
y
Collaboration Diagram
1.1: a
1.2: c
z
x
a
y
b
c
1.1.1:
b
z
Burapha University, 2001
Object-Oriented Analysis and Design
What is a collaboration?
• Collaboration
• กาหนดบทบาท (role) ของกลุ่มของวัตถุทกี่ ระทาต่ องานใดงาน
หนึ่ง เช่ นเดียวกับ operation หรือ use case
• Interaction
• ปฏิสัมพันธ์ ทรี่ ะบุรูปแบบการสื่ อสาร (communication pattern)
ทีก่ ระทาโดยวัตถุที่ กาลังแสดงบทบาทของ collaboration
Burapha University, 2001
Object-Oriented Analysis and Design
Content of Collabaration diagrams
• วัตถุ (Objects)
• แลกเปลีย่ น messages ให้ แก่ กนั และกัน
• Messages
• Synchronous : “call events,” แทนด้ วย full arrow
• Asynchronous: “signals,” แทนด้ วย half arrow
• «create» และ «destroy» messages
• มีการระบุหมายเลข Message ตามลาดับทีเ่ กิดก่ อน-หลัง และ
การอาจมี Loop ของ Message
Burapha University, 2001
Object-Oriented Analysis and Design
Collaboration diagrams
• หมายเลขกากับ แสดงลาดับของ messages ระบุโดย
• 1, 2, 3, 4, …..
• 1, 1.1, 1.2, 1.3, 2, 2.1, 2.1.1, 2.2, 3
(แสดง operation calls ที่เป็ นส่ วนย่ อยของ operation
อืน่ ๆ)
Burapha University, 2001
Object-Oriented Analysis and Design
Collaboration diagram basics
: ProfessorCourseManager
1 : Add professor (Professor)
Math 101 - Section 1 : CourseOffering
Burapha University, 2001
Object-Oriented Analysis and Design
Example : Collaboration diagram
1 : set course info
2 : process
: Registrar
course form : CourseForm
3 : add course
theManager : CurriculumManager
aCourse : Course
4 : <<create>>
Burapha University, 2001
Object-Oriented Analysis and Design
Example : Collaboration diagram
1 : Print(ps-file)
myComputer/PrintClient
: Computer
: Customer
2 : Print(ps-file)
aPrinter : Printer
aQueue : Queue
[printer free]
2.1 : Print(ps-file)
ThePrintServer
: Print Server
[printer busy]
2.1 : Print(ps-file)
Burapha University, 2001
Object-Oriented Analysis and Design
Comparing sequence & collaboration diagrams
• collaboration diagrams อาจแสดง static connections ของวัตถุ
เหมาะสาหรับการแสดงการไหลของการควบคุมการทางาน
• Sequence diagrams เหมาะสาหรับการแสดง กระแสการไหลของ
เหตุการณ์ ทเี่ กิดขึน้ ตามลาดับเวลา
• อาจเข้ าใจได้ ยากกว่ าใน collaboration diagrams
• ปฏิสัมพันธ์ ที่ซับซ้ อน ยากแก่ การทาความเข้ าใจ ไม่ ว่าจะใช้
diagram แบบใด
Burapha University, 2001
Object-Oriented Analysis and Design
Interaction Modeling Tips
• ใช้ เฉพาะส่ วนของวัตถุ Include only those features of the
instances that are relevant.
• แสดง flow จากซ้ ายไปขวา และจากบนลงล่ าง
• ใช้ sequence diagrams
• เพือ่ แสดงลาดับระหว่ างสิ่ งทีม่ ากระตุ้นให้ เกิดปฏิสัมพันธ์
ระหว่ างวัตถุ
• มักใช้ ใน real-time modeling
• ใช้ collaboration diagrams
• เมื่อโครงสร้ างของระบบ มีความสาคัญ
Burapha University, 2001
Object-Oriented Analysis and Design
Example: A Booking System
Burapha University, 2001
Object-Oriented Analysis and Design
Use Case Description: Change Flt Itinerary
• Actors
• traveler, client account db, airline reservation system
• Basic course:
• Traveler เลือก ‘change flight itinerary’ option
• System ดึงค่ า account และ flight itinerary ของ traveler
จาก client account database
• System ถาม traveler ให้ traveler เลือกส่ วนของ itinerary
segment ที่ต้องการเปลีย่ นแปลง
• ...
Burapha University, 2001
Object-Oriented Analysis and Design
Use Case Description: Change Flt Itinerary
• ...
• System ถาม traveler ข้ อมูลเกีย่ วกับเวลา departure และ
destination; traveler เป็ นคนให้ ข้อมูล
• ถ้ า flights ที่ traveler ต้ องการเปลีย่ น ยังมีทวี่ ่ าง ให้ …
•…
• System แสดงสรุปรายการ transaction
• Alternative course:
• ถ้ า flights ที่ traveler ต้ องการเปลีย่ น ไม่ มีทวี่ ่ าง ให้ …
Burapha University, 2001
Object-Oriented Analysis and Design
Sequence Diagram: Change Flight Itinerary
Traveler
: Booking System Client Account DBMSAirline Reservation System
change flight itinerary
get customer account
present itinerary
get itinerary
select segment
present detailed info
update information
available flight
:
:
Burapha University, 2001
Object-Oriented Analysis and Design
Collaboration Diagram: Change Flt Itinerary
1: change flight itinerary
5: select segment
7: update information
2: get customer account
3: get itinerary
: Booking System
4: present itinerary
Traveler6: present detailed info
Client Account DBMS
8: available flight
Airline Reservation System
Burapha University, 2001
Object-Oriented Analysis and Design
Summary
• UML Behavioral Diagrams
• Interaction Diagrams
• Sequence Diagram
• Collaboration Diagram
Burapha University, 2001