Behavioral Diagrams - Interaction Diagrams

Download Report

Transcript Behavioral Diagrams - Interaction Diagrams

วิชาวิเคราะห์ และออกแบบระบบเชิงวัตถุ
Lec08 :: Behavioral Modeling with UML
Behavioral Diagrams
Interaction Diagrams
Nattapong Songneam
[email protected]
http://www.siam2dev.com
Lecture Outline
• UML Behavioral Diagrams
• Interaction Diagrams
• Sequence Diagram
• Collaboration Diagram
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
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
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
Static & Dynamic views
• ระบบใดๆ มักประกอบด้ วยโครงสร้ าง 2 แบบ ได้ แก่
• static และ dynamic
• โครงสร้ างของ Use Case และ Class Diagram เป็ นแบบ static
• แสดงองค์ ประกอบของระบบ คลาส แอททริบิวต์ เมทธอด
และ ความสั มพันธ์ ระหว่ างคลาส
• ไม่ ระบุข้นั ตอนการดาเนินงาน ลาดับการทางานก่ อนหลัง
• โครงสร้ างของ Behavioral Diagrams เป็ นแบบ dynamic
Behavioral Diagrams
• Behavioral Diagrams เป็ นโครงสร้ างแบบ dynamic
• 4 diagrams ได้ แก่
• Sequence Diagram
Interaction Diagrams
• Collaboration Diagram
• State-transition Diagram
• Activity Diagram
Interaction Diagrams
Interaction diagrams
•
•
•
•
แสดงการปฏิสัมพันธ์ ระหว่ างกลุ่มของวัตถุ
มักใช้ อธิบายสถานการณ์ ของ use case 1 use case
อธิบายการติดต่ อสื่ อสารระหว่ างวัตถุ
2 รู ปแบบ
• Time-based (Sequence Diagram)
• Organization-based (Collaboration Diagram)
Sequence & Collaboration Diagrams
• ทั้ง 2 diagrams แสดง message ทีถ่ ูกส่ งผ่ านระหว่ างวัตถุที่
ทางานร่ วมกัน เพือ่ ประกอบเป็ นหน้ าที่การทางานของระบบ
• Sequence diagrams เน้ น message ที่เกิดขึน้ ตามลาดับของ
เวลา
• Collaboration diagrams เน้ นการเชื่อมต่ อทางด้ าน
โครงสร้ างระหว่ างวัตถุทที่ างานร่ วมกัน
Sequence & Collaboration Diagrams
• ทั้ง 2 diagrams สามารถใช้ ในการจาลองการปฏิสัมพันธ์
ระหว่ างวัตถุ กับระบบทั้งหมด
• หรือ อาจใช้ ในการจาลองปฏิสัมพันธ์ ที่เกีย่ วข้ องใน Use Case
ใด Use Case หนึ่งโดยเฉพาะ
A Sequence Diagram
: Student
registration
form
registration
manager
math 101
math 101
section 1
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)
A Collaboration Diagram
1: set course info
2: process
course form :
CourseForm
3: add course
: Registrar
theManager :
CurriculumManager
aCourse :
Course
4: new course
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
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
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
Sequence diagrams
• แสดงการปฏิสัมพันธ์ ระหว่ างวัตถุตามลาดับเวลา (time
sequence)
• ประกอบด้ วย
• actor หรือ object ทีม่ ีปฏิสัมพันธ์ กบั วัตถุอนื่ ๆ
• เส้ นชีวติ (lifeline)
• Message ที่ส่งผ่ านระหว่ าง Object หรือ actor
Content of sequence diagrams
• Actor หรือ วัตถุ (Objects)
• แลกเปลีย่ น messages ให้ แก่กนั และกัน
• เส้ นชีวติ (Lifeline)
• แสดงว่ าวัตถุถูกสร้ างขึน้ และยังไม่ ถูกทาลาย
• Messages
• message ที่ส่งผ่ านระหว่ าง objects สนับสนุนการปฏิสัมพันธ์
ระหว่ างวัตถุ
• เป็ นวิธีการที่ object ใช้ ในการขอรับบริการจากวัตถุอนื่ ๆ
• object ใดๆ ติดต่ อสื่ อสารกับ object อืน่ ๆ ผ่ านทาง operation
ของวัตถุน้ันๆ
• Simple
Message Types
• Sender / Receiver
• ไม่ ระบุรายละเอียดของวิธีการติดต่ อสื่ อสารระหว่ างวัตถุ
• Synchronous
• เรียกใช้ Operation ของวัตถุ โดย Sender/Caller รอจน สิ้นสุ ด
Operation
• Receiver จัดเป็ น passive object
• Asynchronous
• ไม่ มีการ return กลับไปยัง Sender/Caller
• Sender ทางานต่ อทันที่ทสี่ ่ ง message
• Receiver จัดเป็ น active object
Message Notation
Simple
Synchronous
Asynchronous
(Message return)
Notation : Sequence Diagram
object symbol
name : Class
lifeline
activation
other
stimulus
[condition]
name (…)
new (…)
message
: Class
delete
create
return
Example: Different Arrows
Flat Flow
Nested Flow
telle
r
: Order
: Article
getValue
caller
exchange
Asynchronous Flow
callee
lift receiver
dial digit
dial digit
getName
err handl alarm
unknown
alarm
dial tone
price
appl
ringing tone
ringing
signal
lift
receiver
Example: Sequence diagram
: Registrar
course form :
CourseForm
theManager :
CurriculumManager
Set Course Info
Object
creation
process
Add Course
<<create>>
aCourse :
Course
Example: Sequence diagram
Actor
: Customer
: Computer
: Printer
Server
: Printer
: Queue
Print(file)
Print(file)
Message
Lifeline
[Printer free]
Print(file)
[Printer busy]
Print(file)
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
What is a collaboration?
• Collaboration
• กาหนดบทบาท (role) ของกลุ่มของวัตถุทกี่ ระทาต่ องานใดงาน
หนึ่ง เช่ นเดียวกับ operation หรือ use case
• Interaction
• ปฏิสัมพันธ์ ทรี่ ะบุรูปแบบการสื่ อสาร (communication pattern)
ทีก่ ระทาโดยวัตถุที่ กาลังแสดงบทบาทของ collaboration
Content of Collabaration diagrams
• วัตถุ (Objects)
• แลกเปลีย่ น messages ให้ แก่ กนั และกัน
• Messages
• Synchronous : “call events,” แทนด้ วย full arrow
• Asynchronous: “signals,” แทนด้ วย half arrow
• «create» และ «destroy» messages
• มีการระบุหมายเลข Message ตามลาดับทีเ่ กิดก่ อน-หลัง และ
การอาจมี Loop ของ Message
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
อืน่ ๆ)
Collaboration diagram basics
: ProfessorCourseManager
1 : Add professor (Professor)
Math 101 - Section 1 : CourseOffering
Example : Collaboration diagram
1 : set course info
2 : process
: Registrar
course form : CourseForm
3 : add course
theManager : CurriculumManager
aCourse : Course
4 : <<create>>
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)
Comparing sequence & collaboration diagrams
• collaboration diagrams อาจแสดง static connections ของวัตถุ
เหมาะสาหรับการแสดงการไหลของการควบคุมการทางาน
• Sequence diagrams เหมาะสาหรับการแสดง กระแสการไหลของ
เหตุการณ์ ทเี่ กิดขึน้ ตามลาดับเวลา
• อาจเข้ าใจได้ ยากกว่ าใน collaboration diagrams
• ปฏิสัมพันธ์ ที่ซับซ้ อน ยากแก่ การทาความเข้ าใจ ไม่ ว่าจะใช้
diagram แบบใด
Interaction Modeling Tips
• ใช้ เฉพาะส่ วนของวัตถุ Include only those features of the
instances that are relevant.
• แสดง flow จากซ้ ายไปขวา และจากบนลงล่ าง
• ใช้ sequence diagrams
• เพือ่ แสดงลาดับระหว่ างสิ่ งทีม่ ากระตุ้นให้ เกิดปฏิสัมพันธ์
ระหว่ างวัตถุ
• มักใช้ ใน real-time modeling
• ใช้ collaboration diagrams
• เมื่อโครงสร้ างของระบบ มีความสาคัญ
Example: A Booking System
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 ที่ต้องการเปลีย่ นแปลง
• ...
Use Case Description: Change Flt Itinerary
• ...
• System ถาม traveler ข้ อมูลเกีย่ วกับเวลา departure และ
destination; traveler เป็ นคนให้ ข้อมูล
• ถ้ า flights ที่ traveler ต้ องการเปลีย่ น ยังมีทวี่ ่ าง ให้ …
•…
• System แสดงสรุปรายการ transaction
• Alternative course:
• ถ้ า flights ที่ traveler ต้ องการเปลีย่ น ไม่ มีทวี่ ่ าง ให้ …
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
:
:
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
Summary
• UML Behavioral Diagrams
• Interaction Diagrams
• Sequence Diagram
• Collaboration Diagram