interaction diagramitsci.mju.ac.th/sayan/it323/slides/uml_04.pdf · 1 sequence diagrams : 1 use...
TRANSCRIPT
![Page 1: Interaction Diagramitsci.mju.ac.th/sayan/it323/slides/UML_04.pdf · 1 Sequence Diagrams : 1 Use case ในกรณีที่ไม่ใช่1 : 1 จะท าให้ไดอาแกรมมี](https://reader033.vdocuments.mx/reader033/viewer/2022042022/5e79f0203ae9a67bd5138cfa/html5/thumbnails/1.jpg)
Interaction Diagram
Object Oriented Development with UML
By Assoc. Prof. Rangsit Sirirangsi
![Page 2: Interaction Diagramitsci.mju.ac.th/sayan/it323/slides/UML_04.pdf · 1 Sequence Diagrams : 1 Use case ในกรณีที่ไม่ใช่1 : 1 จะท าให้ไดอาแกรมมี](https://reader033.vdocuments.mx/reader033/viewer/2022042022/5e79f0203ae9a67bd5138cfa/html5/thumbnails/2.jpg)
Activity Diagram Statechart Diagram
Package Diagram
Component Diagram
DePloyment Diagram
Sequence Diagram
Class Diagram
Class Diagram
Collaboration Diagram
State Daigram
Implementation
DiagramUsecase Diagram
Use case
Scenerio
Static Structure Diagram
UMLDiagram
Interaction Diagram
![Page 3: Interaction Diagramitsci.mju.ac.th/sayan/it323/slides/UML_04.pdf · 1 Sequence Diagrams : 1 Use case ในกรณีที่ไม่ใช่1 : 1 จะท าให้ไดอาแกรมมี](https://reader033.vdocuments.mx/reader033/viewer/2022042022/5e79f0203ae9a67bd5138cfa/html5/thumbnails/3.jpg)
Static & Dynamic View Static● คลาสไดอาแกรมน าเสนอโครงสรางของระบบแบบ static ในรปของคลาส● โดยมความสมพนธประเภท Dependency, Generalization/Specialization,
Whole/Part, และ Association Dynamic● ใชแสดงพฤตกรรมของระบบทสงผลตอเหตการณและมการเปลยนแปลงเกดขนภายในระบบ
● โดยปกตแลวเปนการน าเสนอการท างานในระดบออปเจค เพอแสดงถงสงทเกดขนกบออปเจค
● การปฏสมพนธกนระหวางออปเจคภายในระบบทมการสงและรบแมสเสจระหวางกน เพอใหเปนไปตามล าดบเหตการณทเกดขนในยสเคส
![Page 4: Interaction Diagramitsci.mju.ac.th/sayan/it323/slides/UML_04.pdf · 1 Sequence Diagrams : 1 Use case ในกรณีที่ไม่ใช่1 : 1 จะท าให้ไดอาแกรมมี](https://reader033.vdocuments.mx/reader033/viewer/2022042022/5e79f0203ae9a67bd5138cfa/html5/thumbnails/4.jpg)
Interaction Diagram
ไดอาแกรมแบบปฏสมพนธ (UML 1.5) ไดแก Sequence Diagram Collaboration Diagram
● ทงสองไดอาแกรมเปนทางเลอกในการน าเสนอการท างานทใชขอมลเดยวกน ไดอาแกรมแบบนจะถกสรางขนส าหรบแตละยสเคส
เพอแสดงถงการท างานในแตละ scenarios ในกรณทยสเคสมการท างานรวมกบยสเคสอน ๆ อาจมการรวบรวมการท างานไวดวยกนได
![Page 5: Interaction Diagramitsci.mju.ac.th/sayan/it323/slides/UML_04.pdf · 1 Sequence Diagrams : 1 Use case ในกรณีที่ไม่ใช่1 : 1 จะท าให้ไดอาแกรมมี](https://reader033.vdocuments.mx/reader033/viewer/2022042022/5e79f0203ae9a67bd5138cfa/html5/thumbnails/5.jpg)
Sequence & Collaboration diagrams
SEQUENCE DIAGRAMS แสดงการปฏสมพนธระหวางออปเจคทถกน าเสนอในรปของtime sequences
น าเสนอออปเจคทมสวนรวมในการปฏสมพนธ
ล าดบของการรบสงแมสเสจ ออปเจคประกอบดวย “lifelines”● การรบสงแมสเสจถกน าเสนอตามล าดบการท างาน
COLLABORATION DIAGRAMS แสดงความสมพนธระหวางออปเจค● เหนภาพความรวมมอระหวางกนไดชดเจนยงขน
● เหนภาพผลกระทบทเกดขนกบออปเจคหนง ๆ ไดชดเจนยงขน
● การแกไขล าดบการท างานของแมสเสจ สามารถท าไดงายขน
ความแตกตางหลกของไดอาแกรมทงสองคอวธการแสดงล าดบของการสงแมสเสจเปนหลก
![Page 6: Interaction Diagramitsci.mju.ac.th/sayan/it323/slides/UML_04.pdf · 1 Sequence Diagrams : 1 Use case ในกรณีที่ไม่ใช่1 : 1 จะท าให้ไดอาแกรมมี](https://reader033.vdocuments.mx/reader033/viewer/2022042022/5e79f0203ae9a67bd5138cfa/html5/thumbnails/6.jpg)
Interaction Diagrams
x y z
Sequence Diagram
a
b
c
Collaboration Diagram
x y
z
1.1: a
1.2: c
1.1.1:
b
y
![Page 7: Interaction Diagramitsci.mju.ac.th/sayan/it323/slides/UML_04.pdf · 1 Sequence Diagrams : 1 Use case ในกรณีที่ไม่ใช่1 : 1 จะท าให้ไดอาแกรมมี](https://reader033.vdocuments.mx/reader033/viewer/2022042022/5e79f0203ae9a67bd5138cfa/html5/thumbnails/7.jpg)
Sequence Diagram
คดคนขนโดย Ivar Jacobson● สงทยากทสดในการโปรแกรมเชงวตถคอ การท าความเขาใจการท างานของกลไกควบคมตาง ๆ ภายในโปรแกรม
● การออกแบบทดอาจมคลาสและเมธอดเปนจ านวนมาก การแสดงรายละเอยดการท างานทงหมดท าไดยาก ดงนนตองใชไดอาแกรมทออกแบบมาโดยเฉพาะ
ชวยในการระบ Responsibility/Operation ใหกบคลาส เพอใชก าหนดวธการทออปเจคในระบบใชในการตดตอกน
1 Sequence Diagrams : 1 Use case ในกรณทไมใช 1 : 1 จะท าใหไดอาแกรมมความซบซอนมากและไมสามารถแสดงการโตตอบระหวางออปเจคไดอยางชดเจนนนเอง
![Page 8: Interaction Diagramitsci.mju.ac.th/sayan/it323/slides/UML_04.pdf · 1 Sequence Diagrams : 1 Use case ในกรณีที่ไม่ใช่1 : 1 จะท าให้ไดอาแกรมมี](https://reader033.vdocuments.mx/reader033/viewer/2022042022/5e79f0203ae9a67bd5138cfa/html5/thumbnails/8.jpg)
Fun Example : Objects
![Page 9: Interaction Diagramitsci.mju.ac.th/sayan/it323/slides/UML_04.pdf · 1 Sequence Diagrams : 1 Use case ในกรณีที่ไม่ใช่1 : 1 จะท าให้ไดอาแกรมมี](https://reader033.vdocuments.mx/reader033/viewer/2022042022/5e79f0203ae9a67bd5138cfa/html5/thumbnails/9.jpg)
Fun Example : Sequence diagram
![Page 10: Interaction Diagramitsci.mju.ac.th/sayan/it323/slides/UML_04.pdf · 1 Sequence Diagrams : 1 Use case ในกรณีที่ไม่ใช่1 : 1 จะท าให้ไดอาแกรมมี](https://reader033.vdocuments.mx/reader033/viewer/2022042022/5e79f0203ae9a67bd5138cfa/html5/thumbnails/10.jpg)
Fun Example : Collaboration diagram
![Page 11: Interaction Diagramitsci.mju.ac.th/sayan/it323/slides/UML_04.pdf · 1 Sequence Diagrams : 1 Use case ในกรณีที่ไม่ใช่1 : 1 จะท าให้ไดอาแกรมมี](https://reader033.vdocuments.mx/reader033/viewer/2022042022/5e79f0203ae9a67bd5138cfa/html5/thumbnails/11.jpg)
Represent External Stimuli with Actor
![Page 12: Interaction Diagramitsci.mju.ac.th/sayan/it323/slides/UML_04.pdf · 1 Sequence Diagrams : 1 Use case ในกรณีที่ไม่ใช่1 : 1 จะท าให้ไดอาแกรมมี](https://reader033.vdocuments.mx/reader033/viewer/2022042022/5e79f0203ae9a67bd5138cfa/html5/thumbnails/12.jpg)
Object & Life Line Notation
การน าเสนอชอของออปเจค:● รปแบบ: [instanceName][:className]● ชอคลาสจะตองเปนชอเดยวกบชอของคลาสทปรากฏอยในคลาสไดอาแกรม
● ชอของออปเจคจะถกก าหนดไว เพอปองกนความสบสนในกรณทมการเรยกใชงานส าหรบหลาย ๆ ออปเจคจากคลาสเดยวกน
สญลกษณ Life-Line ใชสญลกษณเสนประแทนการน าเสนอชวงชวตของออปเจคหนง ๆ ระหวางการปฏสมพนธกน
myBirthdy
:Date
![Page 13: Interaction Diagramitsci.mju.ac.th/sayan/it323/slides/UML_04.pdf · 1 Sequence Diagrams : 1 Use case ในกรณีที่ไม่ใช่1 : 1 จะท าให้ไดอาแกรมมี](https://reader033.vdocuments.mx/reader033/viewer/2022042022/5e79f0203ae9a67bd5138cfa/html5/thumbnails/13.jpg)
Activation Bar Notation
Life Line ใชสญลกษณเสนประแนวตงภายใตแอคเตอรและออปเจค เพอแสดงชวงชวตของแอคเตอร/ออปเจคเหลานน
Activation เปนสญลกษณรปสเหลยมทน าเสนอผาน Life line ทใชในการน าเสนอชวงเวลาในการเรยกใชเมธอดของออปเจคทถกระบ ถอเปนชวงเวลาทออปเจคมการประมวลผล และ/หรอรอการคนคาจากแมสเสจ
:ObjectA
Life LineActivation Bar
![Page 14: Interaction Diagramitsci.mju.ac.th/sayan/it323/slides/UML_04.pdf · 1 Sequence Diagrams : 1 Use case ในกรณีที่ไม่ใช่1 : 1 จะท าให้ไดอาแกรมมี](https://reader033.vdocuments.mx/reader033/viewer/2022042022/5e79f0203ae9a67bd5138cfa/html5/thumbnails/14.jpg)
Message
การปฏสมพนธระหวางสองออปเจคสามารถกระท าผานกลไกทเรยกวาแมสเสจ เปนการสงขอมลจากออปเจคหนงไปยงออปเจคอน ๆ พรอมกบคาดหวงกจกรรมในรปของการกระท าทเกดขน แมสเสจสามารถอยในรปของ signal หรอ call
การรบสงแมสเสจกอใหเกด● การท างานหนง ๆ ถกเรยกใช● มการสงสญญาณเกดขน● ออปเจคถกสรางขน (หรอถกลบออกไป)
ก าหนดบทบาทของผเกยวของในการรบสงแมสเสจ● Sender และ Receiver● การระท าทจะเกดขนเมอมการประมวลผลเมอมการรบสงแมสเสจ
ในกระบวนการใด ๆ แมสเสจจะถกจดเรยงล าดบตามเวลาทถกเรยกใชเปนหลก
![Page 15: Interaction Diagramitsci.mju.ac.th/sayan/it323/slides/UML_04.pdf · 1 Sequence Diagrams : 1 Use case ในกรณีที่ไม่ใช่1 : 1 จะท าให้ไดอาแกรมมี](https://reader033.vdocuments.mx/reader033/viewer/2022042022/5e79f0203ae9a67bd5138cfa/html5/thumbnails/15.jpg)
Arrow
สญลกษณลกศรในแนวนอนสามารถน าเสนอ● การรบสงแมสเสจทเรมตนจาก lifeline ของออปเจคหนงไปยง lifeline ของออปเจคอน ๆ
ก าหนดชอ● ชอของการท างานทถกเรยกใชหรอ● ชอของ Signal
อาจก าหนดชอไวพรอมกบ● เลขล าดบเพอแสดงใหเหนถงล าดบของแมสเสจทเกดการปฏสมพนธทงหมด
อยางไรกตาม เลขล าดบอาจถกละเลยในซเควนซไดอาแกรม เนองจากสญลกษณลกศรแสดงใหเหนถงความสมพนธดงกลาวแลว
![Page 16: Interaction Diagramitsci.mju.ac.th/sayan/it323/slides/UML_04.pdf · 1 Sequence Diagrams : 1 Use case ในกรณีที่ไม่ใช่1 : 1 จะท าให้ไดอาแกรมมี](https://reader033.vdocuments.mx/reader033/viewer/2022042022/5e79f0203ae9a67bd5138cfa/html5/thumbnails/16.jpg)
UML Message Notation
Simple - เปนการสงแมสเสจผานออกไปโดยไมมรายละเอยดประกอบ โดยไมมการคาดหวงวาจะมการสง message กลบคนมา บางครงเรยกวา request
Synchronous - การสงแมสเสจทจ าเปนตองรอจนกวาการท างานของแมสเสจจะสนสดลง เชน ในกรณของการเรยกฟงกชนการท างานยอย
Asynchronous - การสงแมสเสจไปยงออปเจคเพอรองขอบรการอยางใดอยางหนง โดยไมจ าเปนตองรอการตอบสนองแตอยางใด
Return - เปนแมสเสจทใชส าหรบแสดงการตอบ สนองการท างานจากแมสเสจ บางครงเรยกวา response
![Page 17: Interaction Diagramitsci.mju.ac.th/sayan/it323/slides/UML_04.pdf · 1 Sequence Diagrams : 1 Use case ในกรณีที่ไม่ใช่1 : 1 จะท าให้ไดอาแกรมมี](https://reader033.vdocuments.mx/reader033/viewer/2022042022/5e79f0203ae9a67bd5138cfa/html5/thumbnails/17.jpg)
Type Of Messages
object 1 object2 object3
Simple Message
Return Message
Asynchronous
Recursive
Synchronous
![Page 18: Interaction Diagramitsci.mju.ac.th/sayan/it323/slides/UML_04.pdf · 1 Sequence Diagrams : 1 Use case ในกรณีที่ไม่ใช่1 : 1 จะท าให้ไดอาแกรมมี](https://reader033.vdocuments.mx/reader033/viewer/2022042022/5e79f0203ae9a67bd5138cfa/html5/thumbnails/18.jpg)
Synchronous & Simple Messages
teller : Order : Article
Synchronous Flow
getValue
price
setID
appl err handl alarm
Nest Flow
unknown
ring
Price ตองเสรจสมบรณ กอนทteller จะสามารถท างานอนได
Ring ถกประมวลผล ขณะทกลไกควบคมกลบส err handle และ appl
unknown
log
![Page 19: Interaction Diagramitsci.mju.ac.th/sayan/it323/slides/UML_04.pdf · 1 Sequence Diagrams : 1 Use case ในกรณีที่ไม่ใช่1 : 1 จะท าให้ไดอาแกรมมี](https://reader033.vdocuments.mx/reader033/viewer/2022042022/5e79f0203ae9a67bd5138cfa/html5/thumbnails/19.jpg)
Sequence Diagram : First Step
ขนตอนแรกจะเปนการก าหนด external หรอ internal entity ในกรณทเปนแบบ internal กระบวนการตดตอกนอาจเรมตนจาก actor โดยตรงและจะถกก าหนดใหเปน initiator โดยอตโนมต ในกรณทเปนแบบ external อาจจะอยในรปของระบบอน ๆ เปนตน
ขนตอนตอไปจะเปนการระบออปเจคและคลาสทถกน าเสนอการท างานผานแกนในแนวนอน (horizontal axis) เขากบชวงเวลาทถกน าเสนอตามแกนในแนวตง (vertical axis) จะถกแสดงไวในรปของเสนแนวตงเปนชวง ๆ
:Actor
Message/ operation()
ObjectA
![Page 20: Interaction Diagramitsci.mju.ac.th/sayan/it323/slides/UML_04.pdf · 1 Sequence Diagrams : 1 Use case ในกรณีที่ไม่ใช่1 : 1 จะท าให้ไดอาแกรมมี](https://reader033.vdocuments.mx/reader033/viewer/2022042022/5e79f0203ae9a67bd5138cfa/html5/thumbnails/20.jpg)
สญลกษณลกศรจะมจดเรมตนจากออปเจคทท าหนาทเปน sender ไปสนสดทออปเจคทท าหนาทเปน receiver
ลกศรเหลานจะใชส าหรบการน าเสนอการท างาน โดยการเรยกใชงานโดยปกตจะเรมตนจากซายไปขวา
การสงและรบแมสเสจอาจเกดขนภายในตวออปเจคเองสญลกษณลกศรอาจจะเรมตนและสนสดลงภายในออปเจคเดยวกนได
นนคอออปเจคสามารถเรยกใชเมธอดของตวเองได
Reflexive message/ self delegation
Object
message
![Page 21: Interaction Diagramitsci.mju.ac.th/sayan/it323/slides/UML_04.pdf · 1 Sequence Diagrams : 1 Use case ในกรณีที่ไม่ใช่1 : 1 จะท าให้ไดอาแกรมมี](https://reader033.vdocuments.mx/reader033/viewer/2022042022/5e79f0203ae9a67bd5138cfa/html5/thumbnails/21.jpg)
Return Values
การสงและรบแมสเสจอาจเกดขนภายในตวออปเจคเองสญลกษณลกศรอาจจะเรมตนและสนสดลงภายในออปเจคเดยวกนได
การก าหนดคาทคนมากจากการท างานของออปเจค โดยปกตจะถกน าเสนอโดยใชสญลกษณลกศรเสนประเสมอ
:A :B
doYouUnderstand()
Caller
Blocked
return
(optional)
yes
anyQuestion()
![Page 22: Interaction Diagramitsci.mju.ac.th/sayan/it323/slides/UML_04.pdf · 1 Sequence Diagrams : 1 Use case ในกรณีที่ไม่ใช่1 : 1 จะท าให้ไดอาแกรมมี](https://reader033.vdocuments.mx/reader033/viewer/2022042022/5e79f0203ae9a67bd5138cfa/html5/thumbnails/22.jpg)
More on Arrow Label
guard-condition, sequence-expression,
return-value := message-name argument-list
3.7.4: move (5, 7)
[ x < 0 ] C3.1: res := getLocation (fig)
guard sequence number
move (5, 7)
3.7 *[1..5]: move (5, 7) iteration
3.7 [ z > 0 ]: move (5, 7) condition
Examples:
กลไกควบคม (conditions, iteration) สามารถก าหนดรวมไวกบชอของแมสเสจไดดงรปแบบตอไปน
![Page 23: Interaction Diagramitsci.mju.ac.th/sayan/it323/slides/UML_04.pdf · 1 Sequence Diagrams : 1 Use case ในกรณีที่ไม่ใช่1 : 1 จะท าให้ไดอาแกรมมี](https://reader033.vdocuments.mx/reader033/viewer/2022042022/5e79f0203ae9a67bd5138cfa/html5/thumbnails/23.jpg)
Conditional Behaviors
guard condition จะระบไวในเครองหมายกามป สามารถน าเสนอไดในแตละ message โดย message จะถกสงเมอ guard condition ทถกก าหนดไวเปนจรง
การก าหนดเงอนไขใน Sequence Diagram● รปแบบ: ‘[‘ expression ’]’ message-label● แมสเสจจะถกสงออกไปไดตอเมอเงอนไขทก าหนดไวเปนจรง● ตวอยางเชน:
Teller Account
[Balance >0] deposit
![Page 24: Interaction Diagramitsci.mju.ac.th/sayan/it323/slides/UML_04.pdf · 1 Sequence Diagrams : 1 Use case ในกรณีที่ไม่ใช่1 : 1 จะท าให้ไดอาแกรมมี](https://reader033.vdocuments.mx/reader033/viewer/2022042022/5e79f0203ae9a67bd5138cfa/html5/thumbnails/24.jpg)
Control information
การท างานแบบวนซ า (Iteration)● รปแบบ: * [ ‘[‘ expression ‘]’ ] message-label● แมสเสจจะถกสงออกไปหลายครง และมความเปนไปไดทจะมออปเจคในการรบคาหลาย ๆ ออปเจค
Searcher Database
*[value.notFound()] search
![Page 25: Interaction Diagramitsci.mju.ac.th/sayan/it323/slides/UML_04.pdf · 1 Sequence Diagrams : 1 Use case ในกรณีที่ไม่ใช่1 : 1 จะท าให้ไดอาแกรมมี](https://reader033.vdocuments.mx/reader033/viewer/2022042022/5e79f0203ae9a67bd5138cfa/html5/thumbnails/25.jpg)
Focus
of control
Reflexive
message
object
Lifeline
Example of Sequence diagram
Joe AccountJoe : Customer Card Reader ATMScreen Cashdispenser ATMManager
insert cardread card no.
prompt PIN
enter PIN
send card no.
initialize screen
send PIN retrieve PIN
validate PIN
![Page 26: Interaction Diagramitsci.mju.ac.th/sayan/it323/slides/UML_04.pdf · 1 Sequence Diagrams : 1 Use case ในกรณีที่ไม่ใช่1 : 1 จะท าให้ไดอาแกรมมี](https://reader033.vdocuments.mx/reader033/viewer/2022042022/5e79f0203ae9a67bd5138cfa/html5/thumbnails/26.jpg)
Control Information (Cont.)
กลไกควบคมของ sequence diagrams จะด าเนนการไดเฉพาะการท างานทเปนทางเลอกแบบงาย ๆ
พงระลกไวเสมอวา interaction ไดอาแกรมจะมลกษณะแบบ simplicity● ดงนนไมควรใช sequence diagrams ส าหรบการน าเสนอการท างานทมรายละเอยดของอลกอลทมส (การท างานลกษณะดงกลาวสามารถน าเสนอไดดกวาโยใช activity diagrams หรอ state-charts)
![Page 27: Interaction Diagramitsci.mju.ac.th/sayan/it323/slides/UML_04.pdf · 1 Sequence Diagrams : 1 Use case ในกรณีที่ไม่ใช่1 : 1 จะท าให้ไดอาแกรมมี](https://reader033.vdocuments.mx/reader033/viewer/2022042022/5e79f0203ae9a67bd5138cfa/html5/thumbnails/27.jpg)
A Sequence Diagram
member:
LibraryMemberbook:Book
:Book
Copy
borrow(book)
ok = mayBorrow()
[ok] borrow(member)setTaken(member)
X-Axis (objects)
Y-A
xis
(time)
ObjectLife Line
message
Activation box
condition
![Page 28: Interaction Diagramitsci.mju.ac.th/sayan/it323/slides/UML_04.pdf · 1 Sequence Diagrams : 1 Use case ในกรณีที่ไม่ใช่1 : 1 จะท าให้ไดอาแกรมมี](https://reader033.vdocuments.mx/reader033/viewer/2022042022/5e79f0203ae9a67bd5138cfa/html5/thumbnails/28.jpg)
What is a collaboration?
Collaboration: เปนการแสดง roles ของกลม instances ทใชในการท างานหนง ๆ ทเกดขนภายใน use case
Interaction:เปนการตดตอกนระหวาง instances ตาม roles ทก าหนดภายในcollaboration
Role
Class
role name
role namerole name
role name
Actor
Collaboration
![Page 29: Interaction Diagramitsci.mju.ac.th/sayan/it323/slides/UML_04.pdf · 1 Sequence Diagrams : 1 Use case ในกรณีที่ไม่ใช่1 : 1 จะท าให้ไดอาแกรมมี](https://reader033.vdocuments.mx/reader033/viewer/2022042022/5e79f0203ae9a67bd5138cfa/html5/thumbnails/29.jpg)
Collaboration Diagrams
Collaboration ไดอาแกรมจะใชส าหรบแสดงการปฏสมพนธทเกดขนระหวางออปเจค โดยแสดงใหเหนถงการมสวนรวมของออปเจคในการปฏสมพนธโดยใชสญลกษณแสดงการ links ทเกดขนระหวางกน โดยมการสงและรบแมสเสจระหวางกนนนเอง● link จะเปนการแสดงความรวมมอระหวางกน● เนนไปทการแสดง role ของออปเจคแทนทจะเปนเรองของเวลา
การน าเสนอขอมลจะคลายกบ sequence ไดอาแกรม แตจะแตกตางกนตรงทเนนไปทความสมพนธแบบ static ของ class model
มลกษณะใกลเคยงกบ Sequence ไดอาแกรม ดงนนในเครองมอบางแบบสามารถสราง Collaboration จาก Sequence ไดอาแกรมไดอตโนมต
![Page 30: Interaction Diagramitsci.mju.ac.th/sayan/it323/slides/UML_04.pdf · 1 Sequence Diagrams : 1 Use case ในกรณีที่ไม่ใช่1 : 1 จะท าให้ไดอาแกรมมี](https://reader033.vdocuments.mx/reader033/viewer/2022042022/5e79f0203ae9a67bd5138cfa/html5/thumbnails/30.jpg)
The Collaboration : Library System
Customer
asks librarian
for a named
book
The librarian cannot
remember the location
of all books; instead
she collaborates to
find the answer
Find book called “Lady
Chatterley’s Lover”
Answer : F74
Get Book
The librarian mustn’t
leave the front desk;
she collaborates with
an assistant to get the
job done
Assistant, fetch the book from
location F74.
One of the
responsibilities of the
librarian is to check the
book out; this she does
without collaboration
Use Case
Realised!
![Page 31: Interaction Diagramitsci.mju.ac.th/sayan/it323/slides/UML_04.pdf · 1 Sequence Diagrams : 1 Use case ในกรณีที่ไม่ใช่1 : 1 จะท าให้ไดอาแกรมมี](https://reader033.vdocuments.mx/reader033/viewer/2022042022/5e79f0203ae9a67bd5138cfa/html5/thumbnails/31.jpg)
Library Example ยสเคส “Borrow Named Book”
ประกอบไปดวยคลาสดงตอไปน● Librarian, Book Index, Library Assistant, Bookshelves
Librarian
Assistant Bookshelf Book
BookIndex
0..*0..*
finds books from
0..*
1
<is in charge of
1..*
1
can check
1
Customer
Borrow Named Book
![Page 32: Interaction Diagramitsci.mju.ac.th/sayan/it323/slides/UML_04.pdf · 1 Sequence Diagrams : 1 Use case ในกรณีที่ไม่ใช่1 : 1 จะท าให้ไดอาแกรมมี](https://reader033.vdocuments.mx/reader033/viewer/2022042022/5e79f0203ae9a67bd5138cfa/html5/thumbnails/32.jpg)
Objects and Existing Associations
หมายเหต ใน collaboration ไดอาแกรม สงส าคญทสดไดแก ออปเจคไมใชคลาส ซงในกรณนจะเปนจรงเสมอในไดอาแกรมแบบปฏสมพนธ
ออปเจคสงแมสเสจระหวางกนตามความสมพนธทเกดขนในคลาสไดอาแกรม เมอออปเจคหนงตองการเรยกใชเมธอดของอกออปเจคหนง สองออปเจคจะถกเชอมตอดวยสญลกษณเสนตรงระหวางกน
จากนนเพมชอของเมธอดลงบนเสนดงกลาว ในกรณทตองการเพมชอเมธอดใหม สามารถระบไดทนทโดยไมตองใชเสนใหม
:Assistant :BookshelfgetBook
![Page 33: Interaction Diagramitsci.mju.ac.th/sayan/it323/slides/UML_04.pdf · 1 Sequence Diagrams : 1 Use case ในกรณีที่ไม่ใช่1 : 1 จะท าให้ไดอาแกรมมี](https://reader033.vdocuments.mx/reader033/viewer/2022042022/5e79f0203ae9a67bd5138cfa/html5/thumbnails/33.jpg)
Parameters & Return Values
โดยปกตแลวพารามเตอรทถกเรยกใชพรอมกบแมสเสจจะถกระบไวภายในวงเลบโดยการระบตวแปรตามดวยชนดขอมลเสมอ ในกรณทมจ านวนพารามเตอรมากกวาหนงใหคนดวยเครองหมาย Comma
สวนในกรณทตองการแสดงสญลกษณการคนคาจากแมสเสจสามารถใชรปแบบดงตอไปน● return := message (parameter : parameterType) : returnType
:Librarian :BookIndex String:= getLocation(name)
![Page 34: Interaction Diagramitsci.mju.ac.th/sayan/it323/slides/UML_04.pdf · 1 Sequence Diagrams : 1 Use case ในกรณีที่ไม่ใช่1 : 1 จะท าให้ไดอาแกรมมี](https://reader033.vdocuments.mx/reader033/viewer/2022042022/5e79f0203ae9a67bd5138cfa/html5/thumbnails/34.jpg)
Collaborations การปฏสมพนธถกน าเสนอโดยการแสดงแมสเสจลงในออปเจคไดอาแกรม เพอใหสามารถแสดงการท างานแบบพนฐานได ดงนนไดอาแกรมแบบนจงเปนการน าเสนอความรวมมอในการท างานระหวางกน มากกวาทจะเปนการน าเสนอการท างานของออปเจคไดอาแกรมโดยตรง
Collaboration ไดอาแกรมเปนการน าเสนอรายละเอยดทว ๆ ไปของวธการทออปเจคสามารถ linked เขาดวยกนเพอสนบสนนพฤตกรรมการท างานของระบบ
Collaborations ใชส าหรบแสดงรายละเอยดของการปฏสมพนธทก าหนดไวโดยยสเคส● ขณะทคลาสไดอาแกรมใชแสดงรายละเอยดเชงโครงสรางทงหมดของระบบ
Collaborations ถกน าเสนอในรปของ role ไมใชในรปของคลาส เพอใหออปเจคจากคลาสนน ๆ สามารถท างานในการปฏสมพนธตาง ๆ
![Page 35: Interaction Diagramitsci.mju.ac.th/sayan/it323/slides/UML_04.pdf · 1 Sequence Diagrams : 1 Use case ในกรณีที่ไม่ใช่1 : 1 จะท าให้ไดอาแกรมมี](https://reader033.vdocuments.mx/reader033/viewer/2022042022/5e79f0203ae9a67bd5138cfa/html5/thumbnails/35.jpg)
Object Creation
ในกรณของการสรางออปเจคใหม สามารถระบไดโดยใช constructor หรอระบnew หรอ create ทงนขนอยกบผใช
![Page 36: Interaction Diagramitsci.mju.ac.th/sayan/it323/slides/UML_04.pdf · 1 Sequence Diagrams : 1 Use case ในกรณีที่ไม่ใช่1 : 1 จะท าให้ไดอาแกรมมี](https://reader033.vdocuments.mx/reader033/viewer/2022042022/5e79f0203ae9a67bd5138cfa/html5/thumbnails/36.jpg)
Object Creation (cont’d)
การสรางออปเจคใหมใน collaboration ไดอาแกรมมดงตอไปน
![Page 37: Interaction Diagramitsci.mju.ac.th/sayan/it323/slides/UML_04.pdf · 1 Sequence Diagrams : 1 Use case ในกรณีที่ไม่ใช่1 : 1 จะท าให้ไดอาแกรมมี](https://reader033.vdocuments.mx/reader033/viewer/2022042022/5e79f0203ae9a67bd5138cfa/html5/thumbnails/37.jpg)
Iterated Messages
ในกรณทตองการหาคา cost ของ assembly แมสเสจจะถกสงไปยงแตละcomponents ไมวาจะมจ านวนเปนเทาใดกตาม
เพอแสดงใหเหนวาหนงสญลกษณสามารถใชไดกบหลาย ๆ แมสเสจสญลกษณ * จะถกเพมเขาไปเพอระบการสงวาแมสเสจแบบซ า ๆ
![Page 38: Interaction Diagramitsci.mju.ac.th/sayan/it323/slides/UML_04.pdf · 1 Sequence Diagrams : 1 Use case ในกรณีที่ไม่ใช่1 : 1 จะท าให้ไดอาแกรมมี](https://reader033.vdocuments.mx/reader033/viewer/2022042022/5e79f0203ae9a67bd5138cfa/html5/thumbnails/38.jpg)
Iterated Messages (cont’d)
การท างานซ า ๆ ในกรณของ collaboration ไดอาแกรม
![Page 39: Interaction Diagramitsci.mju.ac.th/sayan/it323/slides/UML_04.pdf · 1 Sequence Diagrams : 1 Use case ในกรณีที่ไม่ใช่1 : 1 จะท าให้ไดอาแกรมมี](https://reader033.vdocuments.mx/reader033/viewer/2022042022/5e79f0203ae9a67bd5138cfa/html5/thumbnails/39.jpg)
Conditional Messages (cont’d) แมสเสจทถกเรยกใชแบบ Recursive
![Page 40: Interaction Diagramitsci.mju.ac.th/sayan/it323/slides/UML_04.pdf · 1 Sequence Diagrams : 1 Use case ในกรณีที่ไม่ใช่1 : 1 จะท าให้ไดอาแกรมมี](https://reader033.vdocuments.mx/reader033/viewer/2022042022/5e79f0203ae9a67bd5138cfa/html5/thumbnails/40.jpg)
Conditional Messages (cont’d)
Recursive activations จะไมถกน าเสนอภายใน collaboration ไดอาแกรม แตจะการใชงานของ recursive activation จะมผลตอล าดบของตวเลขทเกดขนในแมสเสจแทนท
![Page 41: Interaction Diagramitsci.mju.ac.th/sayan/it323/slides/UML_04.pdf · 1 Sequence Diagrams : 1 Use case ในกรณีที่ไม่ใช่1 : 1 จะท าให้ไดอาแกรมมี](https://reader033.vdocuments.mx/reader033/viewer/2022042022/5e79f0203ae9a67bd5138cfa/html5/thumbnails/41.jpg)
Interactions - Links
เปนสญลกษณทใชแสดงการเชอมตอระหวางออปเจคโดยการสงแมสเสจระหวางกน
เพอแสดงใหเหนวาคลาสมความสมพนธกน
Person
+ setCom( s : Salary )
+ assign( d : Department )
…
Company1..* *
employee employer
p : Person : Company
assign( development )
named objectlink
anonymous object
message
Class Diagram
Object Diagram
![Page 42: Interaction Diagramitsci.mju.ac.th/sayan/it323/slides/UML_04.pdf · 1 Sequence Diagrams : 1 Use case ในกรณีที่ไม่ใช่1 : 1 จะท าให้ไดอาแกรมมี](https://reader033.vdocuments.mx/reader033/viewer/2022042022/5e79f0203ae9a67bd5138cfa/html5/thumbnails/42.jpg)
Dinner Scenario การท างานประกอบไปดวยสามคลาสไดแก Customer, Waiter และ
Chef โดยมล าดบการท างานดงตอไปน
The customer gives the order to the waiter Waiter will give the order of the food to the chef. Waiter will serve the wine to customer. Chef cooks the order foods. Waiter will pickup the cooked food from the chef and serve it to
the customer The customer will pay to the waiter
![Page 43: Interaction Diagramitsci.mju.ac.th/sayan/it323/slides/UML_04.pdf · 1 Sequence Diagrams : 1 Use case ในกรณีที่ไม่ใช่1 : 1 จะท าให้ไดอาแกรมมี](https://reader033.vdocuments.mx/reader033/viewer/2022042022/5e79f0203ae9a67bd5138cfa/html5/thumbnails/43.jpg)
Example - Dinner
: Customer : Waiter : Chef
order
order food
serve Wine
cooks
pick up food
serve food
pay
![Page 44: Interaction Diagramitsci.mju.ac.th/sayan/it323/slides/UML_04.pdf · 1 Sequence Diagrams : 1 Use case ในกรณีที่ไม่ใช่1 : 1 จะท าให้ไดอาแกรมมี](https://reader033.vdocuments.mx/reader033/viewer/2022042022/5e79f0203ae9a67bd5138cfa/html5/thumbnails/44.jpg)
Example - Vending Machine
CoinCoin Handler
Drink
Customer
Vending Machine
CustomerBuy a Drink
![Page 45: Interaction Diagramitsci.mju.ac.th/sayan/it323/slides/UML_04.pdf · 1 Sequence Diagrams : 1 Use case ในกรณีที่ไม่ใช่1 : 1 จะท าให้ไดอาแกรมมี](https://reader033.vdocuments.mx/reader033/viewer/2022042022/5e79f0203ae9a67bd5138cfa/html5/thumbnails/45.jpg)
Scenario
Basic Flow:1. Customer inserts correct money into the Vending Machine2. Vending Machine get money and pass to Coin Handler to identifies type
of coin.3. Then Vending machine prompt user to select drink.4. Customer selects a drink to the Vending Machine.5. The Vending Machine get command and pass to Coin Handler to check
available drink6. Then a selected drink is dispensed to customer
![Page 46: Interaction Diagramitsci.mju.ac.th/sayan/it323/slides/UML_04.pdf · 1 Sequence Diagrams : 1 Use case ในกรณีที่ไม่ใช่1 : 1 จะท าให้ไดอาแกรมมี](https://reader033.vdocuments.mx/reader033/viewer/2022042022/5e79f0203ae9a67bd5138cfa/html5/thumbnails/46.jpg)
Example - vending machine
: Student: VendingMachine : Coin Handler : Coin : Drink
insertMoney()
moneyIn()
getDrink()
drink
identifyCoin()
selectDrink()
return T/F
getCoin()
promptToSelect()
checkAvailable()
getComand()
![Page 47: Interaction Diagramitsci.mju.ac.th/sayan/it323/slides/UML_04.pdf · 1 Sequence Diagrams : 1 Use case ในกรณีที่ไม่ใช่1 : 1 จะท าให้ไดอาแกรมมี](https://reader033.vdocuments.mx/reader033/viewer/2022042022/5e79f0203ae9a67bd5138cfa/html5/thumbnails/47.jpg)
Class Diagram - Vending Machine
CoinCoin Handler
Drink
Customer
Vending Machine
+insertMoney()
+promptToSelect()
+selectDrink()
+moneyIn()
+identifyCoin()+getCoin()
+getCommand()
+getDrink()
+checkAvailable()
![Page 48: Interaction Diagramitsci.mju.ac.th/sayan/it323/slides/UML_04.pdf · 1 Sequence Diagrams : 1 Use case ในกรณีที่ไม่ใช่1 : 1 จะท าให้ไดอาแกรมมี](https://reader033.vdocuments.mx/reader033/viewer/2022042022/5e79f0203ae9a67bd5138cfa/html5/thumbnails/48.jpg)
Association Customer & Account
ความสมพนธทมลกษณะเปนแบบโครงสรางจะระบโดยออปเจคของคลาสหนงทถก connected ไปยงออปเจคของคลาสทสอง ซงอาจเปนคลาสเดยวกนได
![Page 49: Interaction Diagramitsci.mju.ac.th/sayan/it323/slides/UML_04.pdf · 1 Sequence Diagrams : 1 Use case ในกรณีที่ไม่ใช่1 : 1 จะท าให้ไดอาแกรมมี](https://reader033.vdocuments.mx/reader033/viewer/2022042022/5e79f0203ae9a67bd5138cfa/html5/thumbnails/49.jpg)
Account & Customerclass Account {
private double balance;
public Account() { balance = 0; }public Account(double initialBalance) {
balance = initialBalance;
}public void deposit(double amount) { balance += amount; }
public void withdraw(double amount ) {
balance = balance - amount;
}public double getBalance() { return balance; }
}
class Customer {
private String name;
public Customer(String aName) {
name = aName;
}public String getName() { return name; }
public Account getAccount(Account acc ){ return account; }
}
![Page 50: Interaction Diagramitsci.mju.ac.th/sayan/it323/slides/UML_04.pdf · 1 Sequence Diagrams : 1 Use case ในกรณีที่ไม่ใช่1 : 1 จะท าให้ไดอาแกรมมี](https://reader033.vdocuments.mx/reader033/viewer/2022042022/5e79f0203ae9a67bd5138cfa/html5/thumbnails/50.jpg)
Sequence Diagram
c : Customer acc : Account: main
new Account
deposit
new Customer
getAccount
getBalance
balance
output
getName
println
class Test {
public static void main(String[] args) {
Account acc = new Account();
acc.deposit(500);
Customer c = new Customer("Test");
System.out.println("\nCustomer \"" +
c.getName() );
System.out.println (" has accounts
:"+c.getAccount(acc).getBalance());
}
}
name
println
![Page 51: Interaction Diagramitsci.mju.ac.th/sayan/it323/slides/UML_04.pdf · 1 Sequence Diagrams : 1 Use case ในกรณีที่ไม่ใช่1 : 1 จะท าให้ไดอาแกรมมี](https://reader033.vdocuments.mx/reader033/viewer/2022042022/5e79f0203ae9a67bd5138cfa/html5/thumbnails/51.jpg)
Sequence Diagram
c : Customer acc : Account: main
new Account
deposit
new Customer
getAccountgetBalance
balance
output
getName
println
class Test {
public static void main(String[] args) {
Account acc = new Account();
acc.deposit(500);
Customer c = new Customer("Test");
System.out.println("\nCustomer \"" +
c.getName() + "\"“ + " has accounts
:"+c.getAccount(acc).getBalance());
}
}
}
name
![Page 52: Interaction Diagramitsci.mju.ac.th/sayan/it323/slides/UML_04.pdf · 1 Sequence Diagrams : 1 Use case ในกรณีที่ไม่ใช่1 : 1 จะท าให้ไดอาแกรมมี](https://reader033.vdocuments.mx/reader033/viewer/2022042022/5e79f0203ae9a67bd5138cfa/html5/thumbnails/52.jpg)
Conceptual Class Diagram ภายหลงจากการคนหาคลาสตามหลกการจากบตรดชนซอารซแลว ในขนตอนตอไปจะเปนการน าคลาสทก าหนดไวแลวมาเปลยนใหอยในรปของคลาสไดอาแกรมทประกอบดวยชนดของความสมพนธตาง ๆ ทสามารถน าไปใชเปนแนวทางในขนตอนของการพฒนาตอไป
Product
price : double
pid : Stringpname : String
Order
orderId : String
total : double
lineItems : Vector = new Vector ()
OrderLine
qty : int
sum : double = 0.0
![Page 53: Interaction Diagramitsci.mju.ac.th/sayan/it323/slides/UML_04.pdf · 1 Sequence Diagrams : 1 Use case ในกรณีที่ไม่ใช่1 : 1 จะท าให้ไดอาแกรมมี](https://reader033.vdocuments.mx/reader033/viewer/2022042022/5e79f0203ae9a67bd5138cfa/html5/thumbnails/53.jpg)
Buy Item with Cash
Order
Order no: 1000
Pid Pname Price Qty Sum100 Shirt 800.5 3 2401.5
101 Slack 1250.0 1 1250.0
102 Jacket 1990.0 2 3980.0
Total 7631.50
![Page 54: Interaction Diagramitsci.mju.ac.th/sayan/it323/slides/UML_04.pdf · 1 Sequence Diagrams : 1 Use case ในกรณีที่ไม่ใช่1 : 1 จะท าให้ไดอาแกรมมี](https://reader033.vdocuments.mx/reader033/viewer/2022042022/5e79f0203ae9a67bd5138cfa/html5/thumbnails/54.jpg)
Buy Item with Cash
Order
Order no: 1000
Pid Pname Price Qty Sum
100 Shirt 800.5 3 Price * Qty
101 Slack 1250 1 Price * Qty
Total Sum1+Sum2…
… … … … …
Need method toCalculate Total
Need method toCalculate Sum
![Page 55: Interaction Diagramitsci.mju.ac.th/sayan/it323/slides/UML_04.pdf · 1 Sequence Diagrams : 1 Use case ในกรณีที่ไม่ใช่1 : 1 จะท าให้ไดอาแกรมมี](https://reader033.vdocuments.mx/reader033/viewer/2022042022/5e79f0203ae9a67bd5138cfa/html5/thumbnails/55.jpg)
Implementation Class Diagram
Product
- price : double
- pid : String
- pname : String
+Product()
+getPid()
+getPname()
+getPrice()
Order
- orderId : String
- lineItems : Vector = new Vector ()
+Order()
+addOrderLine()
+calcTotal()
OrderLine
- qty : int
- sum : double = 0.0
+OrderLine()
+getProduct()
+getQty()
+calLineTotal()
![Page 56: Interaction Diagramitsci.mju.ac.th/sayan/it323/slides/UML_04.pdf · 1 Sequence Diagrams : 1 Use case ในกรณีที่ไม่ใช่1 : 1 จะท าให้ไดอาแกรมมี](https://reader033.vdocuments.mx/reader033/viewer/2022042022/5e79f0203ae9a67bd5138cfa/html5/thumbnails/56.jpg)
class Order {
private String orderId;
private Vector lineItems = new Vector();
public Order(String pid ) {
orderId = pid;
}
public void addOrderLine(OrderLine ol) {
lineItems.add(ol);
}
public double calcTotal() {
total = 0.0;
for ( int i = 0; i < lineItems.size(); i++)
total += ((OrderLine)
lineItems.elementAt(i)).calLineTotal();
return total;
}
}
Exercisepublic class OrderLine {
private Product product;
private int qty;
private double sum = 0.0;
public OrderLine() { }
public void addProduct(int amt, Product pro)
{
amount = amt;
product = pro;
}
public Product getProduct() {
return product;
}
public int getQty() {
return qty;
}
public double calLineTotal() {
sum = qty * product.getPrice();
return sum;
}
}
![Page 57: Interaction Diagramitsci.mju.ac.th/sayan/it323/slides/UML_04.pdf · 1 Sequence Diagrams : 1 Use case ในกรณีที่ไม่ใช่1 : 1 จะท าให้ไดอาแกรมมี](https://reader033.vdocuments.mx/reader033/viewer/2022042022/5e79f0203ae9a67bd5138cfa/html5/thumbnails/57.jpg)
class Product {
private String pid, pname;
private double price;
public Product(String pid , String
name, double p ) {
pid = pid;
pname = name;
price = p;
}
public String getPid() {
return pid;
}
public String getPname() {
return pname;
}
public double getPrice() {
return price;
}
}
Exerciseclass RunOrder {
public static void main(String[] args)
{
Product pro1 = new Product("100",
“Shirt", 1400.50);
OrderLine line1 = new OrderLine();
line1.addProduct(3, pro1);
Order o1 = new Order("1000");
o1.addOrderLine(line1);
System.out.println(“ “+
o1.calcTotal());
}
![Page 58: Interaction Diagramitsci.mju.ac.th/sayan/it323/slides/UML_04.pdf · 1 Sequence Diagrams : 1 Use case ในกรณีที่ไม่ใช่1 : 1 จะท าให้ไดอาแกรมมี](https://reader033.vdocuments.mx/reader033/viewer/2022042022/5e79f0203ae9a67bd5138cfa/html5/thumbnails/58.jpg)
: OrderLine: Main
: Order : Product
new Product(pid, name, price)
new OrderLine(amount, pro)
new Order(orderId)
addOrderLine(OrderLine)
calcTotal()
getOrderLine()
calcByLine()
getProduct()getPrice()
price
sum
println
total getAmount()
addProduct()