79
1 บทที่ 5 การวิเคราะหพฤติกรรม (Behavior analysis) 5.1 sequence diagram 5.2 communication diagram 5.3 state chart diagram 5.4 activity diagram 5.5 component diagram 5.6 deployment diagram

บทที่ 5 การวิ ... - cs.science.cmu.ac.th 5.2 communication diagram ... The form then talks to the manager and says “add Joe to Math 101.” The manager tells

Embed Size (px)

Citation preview

Page 1: บทที่ 5 การวิ ... - cs.science.cmu.ac.th 5.2 communication diagram ... The form then talks to the manager and says “add Joe to Math 101.” The manager tells

11

บทท 5 การวเคราะหพฤตกรรม (Behavior analysis)

5.1 sequence diagram5.2 communication diagram

5.3 state chart diagram5.4 activity diagram

5.5 component diagram5.6 deployment diagram

Page 2: บทที่ 5 การวิ ... - cs.science.cmu.ac.th 5.2 communication diagram ... The form then talks to the manager and says “add Joe to Math 101.” The manager tells

2

new

Page 3: บทที่ 5 การวิ ... - cs.science.cmu.ac.th 5.2 communication diagram ... The form then talks to the manager and says “add Joe to Math 101.” The manager tells

33

UML for objected analysis and designRequirementActivity diagrams - ภาพรวมของระบบUse case diagrams - ระบบทาอะไรบาง ใครทาอะไร เกยวพนกนอยางไร :มมมองผใชStructure analysis-Class diagram - model object&class ในระบบBehavior analysis- Sequence diagram - equivalence to Communication diagramเปน diagram มแกนเวลา ทแสดงลาดบการทางานของวตถ มการสง message หากน-Communication diagram - แสดงการทางานรวมกนของ object ในระบบ มลาดบการทางานของวตถ -Statechart diagrams - แสดงสถานะของ object ในระหวางการทางานวาเปนอยางไร มอะไรเกดขนบาง มอะไรมากระตนอธบายการทางานของคลาส-Activity diagrams - แสดงขนตอนการทางานของในเมธอดของ object

Implement diagramComponent diagrams - เปน diagram ทใชอธบายลกษณะทางกายภาพของ system แสดงใหเหนถง สวนประกอบทาง software (Software componentDeployment diagrams - สถาปตยกรรมแบบ physical เปนการมองภาพรวมทงระบบ ท hardware เชอมตอกน

Page 4: บทที่ 5 การวิ ... - cs.science.cmu.ac.th 5.2 communication diagram ... The form then talks to the manager and says “add Joe to Math 101.” The manager tells

44

UML views and diagrams (OMG 13 diagrams)

allow you to model system for many perspectives or views

Structural View

Class diagrams

Object diagrams

User View

Use Case diagrams

Implementation View

Component diagrams

Behavioral View

Sequence diagrams

Communication diagrams

State diagrams

Activity diagrams

Environment View

deployment diagrams

Page 5: บทที่ 5 การวิ ... - cs.science.cmu.ac.th 5.2 communication diagram ... The form then talks to the manager and says “add Joe to Math 101.” The manager tells

55

OMG 13 diagram (3 categories)Structure diagram

class , object , component , composite str.,package , deployment

Behavior diagramuse case (ใชใน phase requirement ได) ,activity , state machine

interaction diagramsequence , communication , timing , interaction overview diagram

Page 6: บทที่ 5 การวิ ... - cs.science.cmu.ac.th 5.2 communication diagram ... The form then talks to the manager and says “add Joe to Math 101.” The manager tells

66

Size of square relative to time spent on workflowh

Inception Elaboration Construction Transition

Project Phases

1 2 3 4 5 6 7 8Iterations within each phaseRequirements

Analysis

Design

Implementation

Test

Workflows

Fountain model

Chapter 2

เรม ละเอยด สราง เปลยน

**ใหสงเกตสงเกต สเหลยมObject-oriented model

Page 7: บทที่ 5 การวิ ... - cs.science.cmu.ac.th 5.2 communication diagram ... The form then talks to the manager and says “add Joe to Math 101.” The manager tells

77

Difference from Waterfall Life Cycle

• In a waterfall life cycle project the phases and the workflows are linked together

• In the Requirements phase, only Requirements workflow activities are carried out

• All Requirements activity should be completed before work starts on Analysis

• In an iterative life cycle project it is recognised that some Requirements work will be happening alongside Analysis work

Page 8: บทที่ 5 การวิ ... - cs.science.cmu.ac.th 5.2 communication diagram ... The form then talks to the manager and says “add Joe to Math 101.” The manager tells

8

Requirements

Analysis

Design

Implementation

Test

Requirements

Analysis

Design

Implementation

Test

Requirement phaseverify

Specification phaseverify

Adapted water fall

Chapter 2

Page 9: บทที่ 5 การวิ ... - cs.science.cmu.ac.th 5.2 communication diagram ... The form then talks to the manager and says “add Joe to Math 101.” The manager tells

99

Not focus on one perspective try to see how they work together

Who or what are you?What do you know?What can you do?

Structure analysis

Behavior analysis

บทท 5 การวเคราะหพฤตกรรม (Behavior analysis)5.1 sequence diagram5.2 communication diagram5.3 state chart diagram5.4 activity diagram5.5 component diagram5.6 deployment diagram

Page 10: บทที่ 5 การวิ ... - cs.science.cmu.ac.th 5.2 communication diagram ... The form then talks to the manager and says “add Joe to Math 101.” The manager tells

1010

5.1 Sequence diagramSequence diagram show object interaction arranged in a time sequence

วตถแตละตวจะตดตอสอสารกนอยางไร มข นตอนการทางานอยางไร เนนทเวลา เวลาเปลยน การทางานเปลยน โดยม actor เปนตวกระตน

model กจกรรมตาง ๆ ของ object ทเกดในระบบแสดงข นตอนการทางาน การสง message ระหวางวตถแตละวตถจะสงขอมลถงกนวาตองทาอะไร เมอไร

ประโยชนของ Sequence diagram คอ ทาใหเราเหนวาในclass diagram ม operation ใดขาดหายไป หรอควรเพมอะไรเขาไป ชวยให class diagram สมบรณมากยงขน

Interaction sequence diagram (or simply a sequence diagram)

Page 11: บทที่ 5 การวิ ... - cs.science.cmu.ac.th 5.2 communication diagram ... The form then talks to the manager and says “add Joe to Math 101.” The manager tells

1111

NotationIn a Sequence diagram, classes and actors are listed as columns, with vertical lifelines indicating the lifetime of the object over time.

ObjectObjects are instances of classes, and are arranged horizontally. The pictorial representation for an Object is a class (a rectangle) with the name prefixed by the object name (optional) and a semi-colon.

ActorActors can also communicate with objects, so they too can be listed as a column. An Actor is modeled using the ubiquitous symbol, the stick figure.

LifelineThe LifeLine identifies the existence of the object over time. The notation for a Lifeline is a vertical dotted line extending from an object.

ActivationActivations, modeled as rectangular boxes on the lifeline, indicate when the object is performing an action.

MessageMessages, modeled as solid horizontal arrows between Activations, indicate the communications between objects.

aObject:Class

: Class

Page 12: บทที่ 5 การวิ ... - cs.science.cmu.ac.th 5.2 communication diagram ... The form then talks to the manager and says “add Joe to Math 101.” The manager tells

1212

ใน Sequence diagram ม 2 แกนแกนต งเปนเวลาแกนนอน แสดงข นตอนการทางานหรอการสงmessageระหวางวตถ แนวต งและแนวนอนตองสมพนธกน

สญลกษณ ใน Sequence diagramรปสเหลยม วตถหรอclassแทนดวยรปสเหลยมเรยงกนตามแนวนอน

ภายในใสชอ object : class (ชอ object อาจละได)

Actor รป stickman ท communicate กบ object

เสนปะ ตามแนวตง แกนเวลา แสดงถงชวตของวตถ

สเหลยมแนวตง ทตรงกบตาแหนงเดยวกบวตถ/class เรยกวา

activation แสดงถงชวงเวลาทวตถกาลงทางาน

เสนลกศร ทาหนาทสงขอความระหวางวตถ (message)

return with value implicit

object creation ----- เสนปะหวลกศรโปรง

aObject : Class

: Class

Page 13: บทที่ 5 การวิ ... - cs.science.cmu.ac.th 5.2 communication diagram ... The form then talks to the manager and says “add Joe to Math 101.” The manager tells

1313

Component of sequence diagram

aObject:Class1

msg1()

msg3()

msg4()

msg5()

msg2()

aObject:Class2

Page 14: บทที่ 5 การวิ ... - cs.science.cmu.ac.th 5.2 communication diagram ... The form then talks to the manager and says “add Joe to Math 101.” The manager tells

1414

Component of sequence diagram

Object1

new()

message( )

delete()

Obj2

response

Object construction and destruction

Page 15: บทที่ 5 การวิ ... - cs.science.cmu.ac.th 5.2 communication diagram ... The form then talks to the manager and says “add Joe to Math 101.” The manager tells

15

Message Passing Syntax

Although the syntax may differ in different langauges, all messages have three identifiable parts:

aGame.displayCard(aCard, 42, 27);

The message receiver The message selector An optional list of arguments

Page 16: บทที่ 5 การวิ ... - cs.science.cmu.ac.th 5.2 communication diagram ... The form then talks to the manager and says “add Joe to Math 101.” The manager tells

1616

Object Messaging

Objects communicate by sending messages.Sending the message getCost() to an Advert object, might use the following syntax.

currentadvertCost = anAdvert.getCost()

:Campaign anAdvert :Advert

getCost()

Page 17: บทที่ 5 การวิ ... - cs.science.cmu.ac.th 5.2 communication diagram ... The form then talks to the manager and says “add Joe to Math 101.” The manager tells

1717

public class Universe {static void main() {

Worker peter = new Worker();Boss boss = new Boss();peter.advise(boss);peter.doWork();

}}

object1:Universe object2:Worker object3:Boss

1:object()2.object()

3.advise(boss)

4.doWork()

5.workStarted()

ความรเดมจากOOP

sequence diagram

Page 18: บทที่ 5 การวิ ... - cs.science.cmu.ac.th 5.2 communication diagram ... The form then talks to the manager and says “add Joe to Math 101.” The manager tells

1818

ตวอยาง หดอาน sequence diagram

Page 19: บทที่ 5 การวิ ... - cs.science.cmu.ac.th 5.2 communication diagram ... The form then talks to the manager and says “add Joe to Math 101.” The manager tells

1919

Sequence diagram ของการตอโทรศพท

:ผตอโทรศพท

ยกห

สญญาณดง

[ยกหกอน 30 วนาท] ตอ connection

: โทรศพทของผตอโทรศพท

: โทรศพทของผรบโทรศพท :ผรบโทรศพท

หมนเบอรโทร

ยกห

[ไมเกน 30 วนาท] สญญาณดง

หดอาน

Page 20: บทที่ 5 การวิ ... - cs.science.cmu.ac.th 5.2 communication diagram ... The form then talks to the manager and says “add Joe to Math 101.” The manager tells

2020

Sequence diagram ของการคยโทรศพทและมสายเรยกซอน

:ผตอโทรศพท

คยรบสญญาณเสยง

[มการเปลยนสาย] ตด connection

: โทรศพทของผตอโทรศพท

: โทรศพทของผรบโทรศพท :ผรบโทรศพท

กดเปลยนสาย

[จบการสนทนา] วางห

มสายเรยกซอน

คยรบสญญาณเสยง

[จบการสนทนา] ตด connection

[จบการสนทนา] วางห

หดอาน

Page 21: บทที่ 5 การวิ ... - cs.science.cmu.ac.th 5.2 communication diagram ... The form then talks to the manager and says “add Joe to Math 101.” The manager tells

2121

:Clients :Console :Monitor :Printer

PressKey(key)

[Key=M] Show()

[Key=P] Print()

Sequence diagram การแสดงผลท monitorและเครองพมพ หดอาน

Page 22: บทที่ 5 การวิ ... - cs.science.cmu.ac.th 5.2 communication diagram ... The form then talks to the manager and says “add Joe to Math 101.” The manager tells

2222

Sequence diagram for invalid PIN

:Client

Insert ATM card

Verify PIN number

Display main screen

: ATMMachine : BankClient

Request PIN

key PIN number

Bad PIN number

Bad PIN number message

Eject ATM card

Request take card

take card

หดอาน

Page 23: บทที่ 5 การวิ ... - cs.science.cmu.ac.th 5.2 communication diagram ... The form then talks to the manager and says “add Joe to Math 101.” The manager tells

2323

แสดงยอดคงเหลอ

Sequence diagram แสดงการขอดยอดเงน

:ผใชเครอง :เครองATM :ป มหมายเลข :หนาจอ

สอดบตร()กด(รหส)

[รหสไมถกตอง] แสดงขอความเตอน

:บญชเงนฝาก

[รหสไมถกตอง] เตอน

[รหสถกตอง] ดาเนนการตอ

[รหสไมถกตอง] หยดการทางาน

แสดง Main menuกด(ขอดเงน)

ตรวจสอบยอดคงเหลอ

หดอาน

Page 24: บทที่ 5 การวิ ... - cs.science.cmu.ac.th 5.2 communication diagram ... The form then talks to the manager and says “add Joe to Math 101.” The manager tells

2424

Sequence diagram ของการถอนเงนดวยเครอง ATM

:ผใชเครอง :เครองATM :ป มหมาย เลข

:หนาจอ :บ/ชเงนฝาก :เครองจายเงน

:เครอง พมพ

สอดบตร

กดรหส(รหส)[รหสไมถกตอง]เตอน

[รหสไมถกตอง]แสดงขอความเตอน

[รหสไมถกตอง]หยดการทารายการ

[รหสถกตอง]ดาเนนการตอ

แสดง main menuกดจานวนเงน(จานวนเงน)

ตรวจสอบยอดเงนคงเหลอ(จานวนเงน)

[จน.เงน<=ยอดคงคาง]จายเงน

พมพ slip[จน.เงน>ยอดคงคาง]แสดง error message

หดอาน

Page 25: บทที่ 5 การวิ ... - cs.science.cmu.ac.th 5.2 communication diagram ... The form then talks to the manager and says “add Joe to Math 101.” The manager tells

2525

Sequence diagram for new Advert to campaign

: Client

getName()

addNewAdvert()Advert()

:Campaign :Advert

getAdvertDetails()

CampaignManager

listCampaigns()getCampaignDetail()

listAdverts()

newAd:Advert

การทางานตองสมพนธกบ Prototype :ตย.นยงไมมจอภาพ

หดอาน

Page 26: บทที่ 5 การวิ ... - cs.science.cmu.ac.th 5.2 communication diagram ... The form then talks to the manager and says “add Joe to Math 101.” The manager tells

26

Sequence diagram for check campaign budget

: Client

getName()

getOverheads()

:Campaign :Advert

getCost()

campaign manager

listCampaigns()getCampaignDetails()

checkCampaignBudget()

การทางานตองสมพนธกบ Prototype :ตย.นยงไมมจอภาพ

Page 27: บทที่ 5 การวิ ... - cs.science.cmu.ac.th 5.2 communication diagram ... The form then talks to the manager and says “add Joe to Math 101.” The manager tells

2727

Sequence diagram for student registration:

RegistrationManager

:Student :Course

s:=findStudent("Jim")registerStudent("Jim","UML")

aStudent:=find("Jim")

[s&c] ok

Registrar

c:=findCourse("UML")

aCourse:=find("UML")

[s&c]register(aStudent)

[(!c) & (!s)] notFound

[(!s) & c] studentnotFound

[(!c) & s] coursenotFound

Page 28: บทที่ 5 การวิ ... - cs.science.cmu.ac.th 5.2 communication diagram ... The form then talks to the manager and says “add Joe to Math 101.” The manager tells

2828

Sequence diagram for reserve article

:Article Reservation

reserve()

:Order :OrderPosition

giveArticle()

giveOrderPos()

: ArticleStock

opos

article

giveNumber()

number

reserve(article,number)

Description

request orderspositions from Order

split order position into article and number

reserve correspondingnumber of articlesin stock

Page 29: บทที่ 5 การวิ ... - cs.science.cmu.ac.th 5.2 communication diagram ... The form then talks to the manager and says “add Joe to Math 101.” The manager tells

2929

Additional Example

Page 30: บทที่ 5 การวิ ... - cs.science.cmu.ac.th 5.2 communication diagram ... The form then talks to the manager and says “add Joe to Math 101.” The manager tells

3030

Sequence diagram แสดงลบ user

Page 31: บทที่ 5 การวิ ... - cs.science.cmu.ac.th 5.2 communication diagram ... The form then talks to the manager and says “add Joe to Math 101.” The manager tells

3131

Page 32: บทที่ 5 การวิ ... - cs.science.cmu.ac.th 5.2 communication diagram ... The form then talks to the manager and says “add Joe to Math 101.” The manager tells

3232

sameOK

Page 33: บทที่ 5 การวิ ... - cs.science.cmu.ac.th 5.2 communication diagram ... The form then talks to the manager and says “add Joe to Math 101.” The manager tells

3333

sameOK

Page 34: บทที่ 5 การวิ ... - cs.science.cmu.ac.th 5.2 communication diagram ... The form then talks to the manager and says “add Joe to Math 101.” The manager tells

3434

Page 35: บทที่ 5 การวิ ... - cs.science.cmu.ac.th 5.2 communication diagram ... The form then talks to the manager and says “add Joe to Math 101.” The manager tells

3535

Page 36: บทที่ 5 การวิ ... - cs.science.cmu.ac.th 5.2 communication diagram ... The form then talks to the manager and says “add Joe to Math 101.” The manager tells

3636

User Interface::AddAdvertUI

boundary class

Campaign

entity class

AddAvert

control class

สญลกษณเพม

for more next page

เวลาเราเขยน Sequence diagram ดานบน วตถหรอ class ทเรยงตามแนวนอนดานบน อาจเขยนดงน

Page 37: บทที่ 5 การวิ ... - cs.science.cmu.ac.th 5.2 communication diagram ... The form then talks to the manager and says “add Joe to Math 101.” The manager tells

3737

Class Diagram: Stereotypes

Alternative notations for entity class:

Campaign

Campaign

titlecampaignStartDatecampaignFinishDate

getCampaignAdverts( )addNewAdvert( )

<<entity>> Campaign

titlecampaignStartDatecampaignFinishDate

getCampaignAdverts( )addNewAdvert( )

สญลกษณเพม

Page 38: บทที่ 5 การวิ ... - cs.science.cmu.ac.th 5.2 communication diagram ... The form then talks to the manager and says “add Joe to Math 101.” The manager tells

3838

Class Diagram: Stereotypes

User Interface::AddAdvertUI

User Interface::AddAdvertUI

startInterface( )assignStaff( )selectClient( )selectCampaign( )

<<boundary>>User Interface::AddAdvertUI

startInterface( )assignStaff( )selectClient( )selectCampaign( )

Alternative notations for boundary class:สวนตดตอ

สญลกษณเพม

Page 39: บทที่ 5 การวิ ... - cs.science.cmu.ac.th 5.2 communication diagram ... The form then talks to the manager and says “add Joe to Math 101.” The manager tells

3939

Class Diagram: Stereotypes

Alternative notations for control class:

AddAvert

Control::AddAdvert

showClientCampaigns( )showCampaignAdverts( )createNewAdvert( )

<<control>>Control::AddAdvert

showClientCampaigns( )showCampaignAdverts( )createNewAdvert( )

สวนควบคม

สญลกษณเพม

Control class are responsible for controlling the flow of event. They transfer the control to the appropriate entity classes depending on the input received from the boundary classes.

Page 40: บทที่ 5 การวิ ... - cs.science.cmu.ac.th 5.2 communication diagram ... The form then talks to the manager and says “add Joe to Math 101.” The manager tells

40

Page 41: บทที่ 5 การวิ ... - cs.science.cmu.ac.th 5.2 communication diagram ... The form then talks to the manager and says “add Joe to Math 101.” The manager tells

4141

Sequence diagrams are used to display the interaction between users, screens, objects and entities within the system. It provides a sequential map of message passing between objects over time. Frequently these diagrams are placed under Use Cases in the model to illustrate the use case scenario - how a user will interact with the system and what happens internally to get the work done. Often, the objects are represented using special stereotyped icons, as in the example below. The object labelled Login Screen is shown using the User Interface icon. The object labelled SecurityManager is shown using the Controller icon. The Object labelled users is shown using the Entity icon.

อาน

Page 42: บทที่ 5 การวิ ... - cs.science.cmu.ac.th 5.2 communication diagram ... The form then talks to the manager and says “add Joe to Math 101.” The manager tells

4242

p.1/2

How to create CD-sale report

Page 43: บทที่ 5 การวิ ... - cs.science.cmu.ac.th 5.2 communication diagram ... The form then talks to the manager and says “add Joe to Math 101.” The manager tells

4343

p.2/2

Page 44: บทที่ 5 การวิ ... - cs.science.cmu.ac.th 5.2 communication diagram ... The form then talks to the manager and says “add Joe to Math 101.” The manager tells

4444

Enrolling in a seminar

Page 45: บทที่ 5 การวิ ... - cs.science.cmu.ac.th 5.2 communication diagram ... The form then talks to the manager and says “add Joe to Math 101.” The manager tells

4545

Outputting transcripts.

Page 46: บทที่ 5 การวิ ... - cs.science.cmu.ac.th 5.2 communication diagram ... The form then talks to the manager and says “add Joe to Math 101.” The manager tells

4646

Case study : Course registration system by Terry Quatrani

sequence diagramsare great tools in the beginning because they show

you and your customer step-by-step what has to happen

Figure shows how a student successfully gets added to a course. The student (let’s call him Joe) fills in some information and submits the form. The form then talks to the manager and says “add Joe to Math 101.” The manager tells Math 101 that it has to add a student. Math 101 says to Section 1 “are you open?” In this case, Section 1 replies that they are open, so Math 101 tells section 1 to add this student

Page 47: บทที่ 5 การวิ ... - cs.science.cmu.ac.th 5.2 communication diagram ... The form then talks to the manager and says “add Joe to Math 101.” The manager tells

4747

:Student:RegistrationForm

:RegistrationManager

:Math101. :Math101Section1

1:fill in info

2:sumit3:add student to math101

4:add student5:are you open?

6:add student

Figure shows how a student successfully gets added to a course.

Page 48: บทที่ 5 การวิ ... - cs.science.cmu.ac.th 5.2 communication diagram ... The form then talks to the manager and says “add Joe to Math 101.” The manager tells

4848

you can use sequence diagrams to drive out testable user interface requirements.

Sequence diagrams good for showing what’s going onfor driving out requirementsand for working with customers.

That usually leads to the question, though, of how many do you need to create? My answer is, “until you do enough.”

do a sequence diagram for every basic flow of every use case.

Page 49: บทที่ 5 การวิ ... - cs.science.cmu.ac.th 5.2 communication diagram ... The form then talks to the manager and says “add Joe to Math 101.” The manager tells

4949

UML for objected analysis and designRequirementActivity diagrams - ภาพรวมของระบบUse case diagrams - ระบบทาอะไรบาง ใครทาอะไร เกยวพนกนอยางไร :มมมองผใชStructure analysis-Class diagram - model object&class ในระบบBehavior analysis- Sequence diagram - equivalence to Communication diagramเปน diagram มแกนเวลา ทแสดงลาดบการทางานของวตถ มการสง message หากน-Communication diagram - แสดงการทางานรวมกนของ object ในระบบ มลาดบการทางานของวตถ -Statechart diagrams - แสดงสถานะของ object ในระหวางการทางานวาเปนอยางไร มอะไรเกดขนบาง มอะไรมากระตนอธบายการทางานของคลาส-Activity diagrams - แสดงขนตอนการทางานของในเมธอดของ object

Implement diagramComponent diagrams - เปน diagram ทใชอธบายลกษณะทางกายภาพของ system แสดงใหเหนถง สวนประกอบทาง software (Software componentDeployment diagrams - สถาปตยกรรมแบบ physical เปนการมองภาพรวมทงระบบ ท hardware เชอมตอกน

Now

Page 50: บทที่ 5 การวิ ... - cs.science.cmu.ac.th 5.2 communication diagram ... The form then talks to the manager and says “add Joe to Math 101.” The manager tells

5050

• ตวอยาง ภาษาไทยเลมกตต แจกsheet (caseStudyKitSEQ.ppt)

• ตวอยางการaddของนศ.มช:use case ข นตอน prototype class di Seq.di.

• ตวอยาง เพมเตมอนๆhttp://www.cs.gordon.edu/courses/cps122/AddressBookExample/index.htmlhttp://www.cs.gordon.edu/courses/cps122/ATMExample/index.htmlAddressbookEx.docATMEx.doc

aObject:Class1

msg1()

msg3()

msg4()

msg5()

msg2()

aObject:Class2

Page 51: บทที่ 5 การวิ ... - cs.science.cmu.ac.th 5.2 communication diagram ... The form then talks to the manager and says “add Joe to Math 101.” The manager tells

5151

เพมเตม UML 2.0sequence diagram ใชเพอแสดงการตดตอระหวาง entity UML 2.0 sequence diagram มคณสมบตเพมเขามาคอ

การเรยกใช interaction ทตองการจากไดอะแกรม เพอนาไปใช ในไดอะแกรมอนหรอเพอนาขอมลมาใชงานได เรยกความสามารถนวา interaction occurrence

Headingบอกชนดไดอะแกรมทใชงานอย

Page 52: บทที่ 5 การวิ ... - cs.science.cmu.ac.th 5.2 communication diagram ... The form then talks to the manager and says “add Joe to Math 101.” The manager tells

5252

sd Room Reservatin Process

:System:Credit CardAuthorization

System

:Potential GuestI want to reserve the room

Request room type &Reservation span

Identify room type &Reservation span

Indicate possible choices

Select room

Request billing information

Provide bill informationRequest for credit cardvalidation(fee,billInfo)

Transaction validated(authCode)Reservation is guaranteed

(reservationConfirmVal)

มการตรวจสอบ credit card

แนวทางการทา

seq di.รปน

เปนแนวคดเปน

กระดาษทด

Page 53: บทที่ 5 การวิ ... - cs.science.cmu.ac.th 5.2 communication diagram ... The form then talks to the manager and says “add Joe to Math 101.” The manager tells

5353

sd Validate credit card

:System:Credit CardAuthorization

System

Request for credit cardvalidation(fee,billInfo)

Validation result(status=OK,authCode)

Page 54: บทที่ 5 การวิ ... - cs.science.cmu.ac.th 5.2 communication diagram ... The form then talks to the manager and says “add Joe to Math 101.” The manager tells

5454

sd Room Reservatin Process

:System:Credit CardAuthorization

System

:Potential GuestI want to reserve the room

Request billing information

Provide bill information

create(DateRange,room,billingInfo )

ReservationConfirmValReservation confirm

(reservationConfirmVal)

RefValidate credit card

:Reservation

Page 55: บทที่ 5 การวิ ... - cs.science.cmu.ac.th 5.2 communication diagram ... The form then talks to the manager and says “add Joe to Math 101.” The manager tells

5555

การอางอง interaction ใสการอางองใหถกตอง วธนจะชวยลดความซาซอนและทาใหเขาใจงาย

UML 2.0 ม operator opt ตวเลอก เพอบอกวา frame นนไมถกใชเมอใด ซงมการกาหนด explicit guard

ในวงเลบกามป explicit guard ทาหนาทกรองวาเฟรมนนจะถกใชเมอคาของ explicit guard เปนไปตามเงอนไข

loop การทาซา loop minint, maxint, [guard]

alt ทางเลอกอน กรณเรามทางเลอกมากกวาสองเสนทาง มการแบงสวนภายใน เพม guard [else] เขาไป

Page 56: บทที่ 5 การวิ ... - cs.science.cmu.ac.th 5.2 communication diagram ... The form then talks to the manager and says “add Joe to Math 101.” The manager tells

5656

sd Room Reservatin Process

:System:Credit CardAuthorization

System

:Potential GuestI want to reserve the room

Request billing information

Provide bill information

<<Craete>>create(DateRange,room,

billingInfo )

ReservationConfirmValReservation confirm

(reservationConfirmVal)

RefSystem.Transaction.Status=Validation

Credit Card(fee,billingInfo,System.Transaction.AC=authCode):OK

:Reservation

Status=OKopt

ตวอยาง การใช operator opt

Page 57: บทที่ 5 การวิ ... - cs.science.cmu.ac.th 5.2 communication diagram ... The form then talks to the manager and says “add Joe to Math 101.” The manager tells

5757

sd Room Reservatin Process

:System:Credit Card

Authorization System

:Potential Guest

I want to reserve the room

Request billing information

Provide bill information

<<Craete>>

create(DateRange,room,

billingInfo )

ReservationConfirmVal

Reservation confirm (reservationConfirmVal)

RefSystem.Transaction.Status=Validation

Credit Card(fee,billingInfo,System.Transaction.AC

=authCode):OK

:ReservationStatus=OK

opt

step 1,3[status=BAD]

breakcancel

sorry,please try again later.

[else]

ตวอยาง การใช operator loop alt

Page 58: บทที่ 5 การวิ ... - cs.science.cmu.ac.th 5.2 communication diagram ... The form then talks to the manager and says “add Joe to Math 101.” The manager tells

5858

จากประสบการณการสอน sequence diagram พบวา

นศ. Very good at thinking in logical mannerand/or good at writing software code

การ create sequence diagram

: เรมจาก identify scope of : what I’m trying to model

The heart of the diagram is in the message

Page 59: บทที่ 5 การวิ ... - cs.science.cmu.ac.th 5.2 communication diagram ... The form then talks to the manager and says “add Joe to Math 101.” The manager tells

5959

เพมเตมจาก sequence diagram

หากซบซอน abstractขน

เราจะสราง Interaction overview diagram

Page 60: บทที่ 5 การวิ ... - cs.science.cmu.ac.th 5.2 communication diagram ... The form then talks to the manager and says “add Joe to Math 101.” The manager tells

6060

OMG 13 diagram (3 categories)Structure diagram

class , object , component , composite str.,package , deployment

Behavior diagramuse case (ใชใน phase requirement ได) ,activity , state machine

interaction diagramsequence , communication , timing , interaction overview diagram

Page 61: บทที่ 5 การวิ ... - cs.science.cmu.ac.th 5.2 communication diagram ... The form then talks to the manager and says “add Joe to Math 101.” The manager tells

6161

Sequence diagram

:Client :Campaign :AdvertgetName

listCampaigns

listAdverts

AdvertnewAd:Advert

addNewAdvert

Lifeline Activation or Execution Object creation

:CampaignManager

sd Add a new advert to a campaign

loop

loop

Interaction Operator

Interaction Constraint

Combined Fragment(loop)[For all client’s campaigns]

getCampaignDetails

[For all campaign’s adverts] getAdvertDetails

Sequence diagram is enclosed in aframe

Frame label

เดม ตอนเรมคด

Page 62: บทที่ 5 การวิ ... - cs.science.cmu.ac.th 5.2 communication diagram ... The form then talks to the manager and says “add Joe to Math 101.” The manager tells

6262

:Client :Campaign :Advert

listCampaigns

listAdverts

AdvertnewAd:Advert

:CampaignManager

sd Add a new advert to a campaign

loop

loop

:AddAdvertUI

:AddAdvert

addNewAdvert

getClient

selectClient

loop

selectCampaign

addNewAdvert

getCampaignDetails

startInterface

[For all clients]

showClientCampaigns

showCampaignAdverts

createNewAdvert

[For all client’s campaigns]

[For all campaign’s adverts]

getAdvertDetails

Boundarylifeline

Controllifeline

Now ปรบsd มจอภาพกอน startInterface ไปดงclientเดม ตอนเรมคด

Page 63: บทที่ 5 การวิ ... - cs.science.cmu.ac.th 5.2 communication diagram ... The form then talks to the manager and says “add Joe to Math 101.” The manager tells

6363

Object Selector Notation

:Client campaign[i]:Campaign

advert[j]:Advert

getName

listCampaigns

checkCampaignBudget

getCampaignDetails

getCost

:CampaignManager

sd Check campaign budget

loop

loop

getOverheads

[i=1;i<=campaign.count; i++ ]

[j=1;j<=advert.count; j++ ]

Object selector notation

Interaction constraint refers to variable used in object selector notation

Page 64: บทที่ 5 การวิ ... - cs.science.cmu.ac.th 5.2 communication diagram ... The form then talks to the manager and says “add Joe to Math 101.” The manager tells

6464

Interaction Operators

:Client campaign[i]:Campaign

advert[j]:Advert

getName

listCampaigns

checkCampaignBudget

getCampaignDetails

getCost

:CampaignManager

sd Check campaign budget

getOverheads

loop (1, *)

Interaction Operator with parameters

loop (1, *)

[i<=campaign.count ]

[ j<=advert.count ]

Page 65: บทที่ 5 การวิ ... - cs.science.cmu.ac.th 5.2 communication diagram ... The form then talks to the manager and says “add Joe to Math 101.” The manager tells

6565

:Client :Campaign :AdvertgetName

listCampaigns ref

ref

:CampaignManager

Advert

addCostedAdvert

newAd:Advert

newRequest:Request

alt

[else]

sd Add a new advert to a campaign if within budget

List client campaigns

[totalCost <= budget]

Request

Get campaign budget

alt interaction operator shows branching

Two interaction operands, one for each

alternativeอาน

Page 66: บทที่ 5 การวิ ... - cs.science.cmu.ac.th 5.2 communication diagram ... The form then talks to the manager and says “add Joe to Math 101.” The manager tells

6666

:Client :Campaign :AdvertgetName

listCampaigns

:CampaignManager

sd Check campaign budget

ref

ref

Gate showing the message enter this interaction occurrence

List client campaigns

Get campaign budget

ref interaction operator indicates interaction occurrence that references an interaction fragment

Next slide

Next slide

Page 67: บทที่ 5 การวิ ... - cs.science.cmu.ac.th 5.2 communication diagram ... The form then talks to the manager and says “add Joe to Math 101.” The manager tells

6767

Interaction Fragment

:Client :Campaign

listCampaigns

getCampaignDetails

sd List client campaigns

loop

Gate showing the message enter this Interaction Fragment

[For all client’s campaigns]

Interaction fragment that is referenced in

Check campaign budgetsequence diagram

Page 68: บทที่ 5 การวิ ... - cs.science.cmu.ac.th 5.2 communication diagram ... The form then talks to the manager and says “add Joe to Math 101.” The manager tells

6868

Interaction Fragment

:Campaign :Advert

getCost

sd Get campaign budget

loop

getOverheads

checkCampaignBudget

:CampaignManager

[For all campaign’s adverts]

Interaction fragment that is also referenced in

Check campaign budgetsequence diagram

Page 69: บทที่ 5 การวิ ... - cs.science.cmu.ac.th 5.2 communication diagram ... The form then talks to the manager and says “add Joe to Math 101.” The manager tells

:Client :Campaign :AdvertgetName

listCampaigns ref

:CampaignManager

alt

[else]

sd Add a new advert to a campaign if within budget

List client campaigns

[totalCost <= budget]ref

Create advert

Create requestref

ref

Get campaign budget

addCostedAdvert

1

2

3

4

ตย.การเขยน

Page 70: บทที่ 5 การวิ ... - cs.science.cmu.ac.th 5.2 communication diagram ... The form then talks to the manager and says “add Joe to Math 101.” The manager tells

70

:Client :Campaign

listCampaigns

getCampaignDetails

sd List client campaigns

loop [For all client’s campaigns]

Interaction Fragment Used1

Page 71: บทที่ 5 การวิ ... - cs.science.cmu.ac.th 5.2 communication diagram ... The form then talks to the manager and says “add Joe to Math 101.” The manager tells

Interaction Fragment Used

:Campaign :Advert

getCost

sd Get campaign budget

loop

getOverheads

checkCampaignBudget

:CampaignManager

[For all campaign’s adverts]

2

Page 72: บทที่ 5 การวิ ... - cs.science.cmu.ac.th 5.2 communication diagram ... The form then talks to the manager and says “add Joe to Math 101.” The manager tells

Interaction Fragment Used

:Campaign :Advert

Advert newAd:Advert

sd Create advert

3

Page 73: บทที่ 5 การวิ ... - cs.science.cmu.ac.th 5.2 communication diagram ... The form then talks to the manager and says “add Joe to Math 101.” The manager tells

Interaction Fragment Used

:Campaign :Advert

newRequest:RequestRequest

sd Create request

4

Page 74: บทที่ 5 การวิ ... - cs.science.cmu.ac.th 5.2 communication diagram ... The form then talks to the manager and says “add Joe to Math 101.” The manager tells

Timing Diagrams

• A new feature in UML 2.0• Show how time constraints affect

interactions between lifelines• The sequence diagram Car enters car park is the basis for the subsequent timing diagram

Page 75: บทที่ 5 การวิ ... - cs.science.cmu.ac.th 5.2 communication diagram ... The form then talks to the manager and says “add Joe to Math 101.” The manager tells

Timing Diagrams:TicketMachine :Barrier after:WeightSensor

sd Car enters car park

raiseBarrier

lowerBarrier

before:WeightSensor

activate

Raised

Lowered

LoweredActive

deactivate

Blocked

barrierLowered

Inactive

ticketRequested

สญลกษณ เปนแนวคด วาเกดอะไร หากมการกระตน เพอนามาเขยน Timing Diagram

1.แผงกนระดบlower2.จบนน.ได TicketMa กactive3.reqตว แผงยก4.Sensor mas-- TicketMadeactivate TicketMa Block5.แผงกนลง6.TicketMa..inactive

Page 76: บทที่ 5 การวิ ... - cs.science.cmu.ac.th 5.2 communication diagram ... The form then talks to the manager and says “add Joe to Math 101.” The manager tells

Timing Diagrams

sd Car enters car park lifelines :Barrier, :TicketMachine

:Bar

rier

:Tic

ketM

achi

ne

Lowered

Raised

Inactive

Active

Blocked

t

{t..t+3s}Timing Constraint

raiseBarrier

barrierLowered

Diagram has two instances, one for

each lifeline

Sloped line represents duration

of state change

Message from one lifeline to another

Page 77: บทที่ 5 การวิ ... - cs.science.cmu.ac.th 5.2 communication diagram ... The form then talks to the manager and says “add Joe to Math 101.” The manager tells

Timing Diagrams

sd Car enters car park lifelines :Barrier, :TicketMachine

:Bar

rier

:Tic

ketM

achi

ne

Lowered

Raised

Inactive

Active

Blocked

ตย.

Page 78: บทที่ 5 การวิ ... - cs.science.cmu.ac.th 5.2 communication diagram ... The form then talks to the manager and says “add Joe to Math 101.” The manager tells

References

• UML Reference Manual (OMG, 2004)• Bennett, Skelton and Lunn (2005)

(For full bibliographic details, see Bennett, McRobb and Farmer)

Page 79: บทที่ 5 การวิ ... - cs.science.cmu.ac.th 5.2 communication diagram ... The form then talks to the manager and says “add Joe to Math 101.” The manager tells

7979

ตอนน

use caseclass diagramsequence

ตย. Project

Part ตอไปจะเรยน 5.2 communication diagramจากนนเราศกษาและชใหเหนความสมพนธของ

use caseclass diagramsequence / communication diagram

การวเคราะหพฤตกรรมเพอหาattribute/method ของ class diagram ทสมบรณขน