object oriented development with uml requirements with use ... · what are the main sources of...

62
Requirements with Use Case Object Oriented Development with UML By- Assoc. Prof. Rangsit Sirirangsi

Upload: others

Post on 01-Nov-2019

2 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Object Oriented Development with UML Requirements with Use ... · What are the main sources of bugs? (source: "Software Testing", Ron Patton) Bugs . เกิดขึ้นได้จากหลาย

Requirements with Use Case

Object Oriented Development with UML

By-

Assoc. Prof. Rangsit Sirirangsi

Page 2: Object Oriented Development with UML Requirements with Use ... · What are the main sources of bugs? (source: "Software Testing", Ron Patton) Bugs . เกิดขึ้นได้จากหลาย
Page 3: Object Oriented Development with UML Requirements with Use ... · What are the main sources of bugs? (source: "Software Testing", Ron Patton) Bugs . เกิดขึ้นได้จากหลาย

The software development process

Maintenance67% Integration

8%

Testing7%

Implementation5%

Design6%

Requirements 7%

Page 4: Object Oriented Development with UML Requirements with Use ... · What are the main sources of bugs? (source: "Software Testing", Ron Patton) Bugs . เกิดขึ้นได้จากหลาย

What are the main sources of bugs?

(source: "Software Testing", Ron Patton)

Bugs เกดขนไดจากหลาย ๆ สาเหต แตสาเหตหลกสามารถตรวจสอบไดจาก

specification

Code7% Other

10%

Design27%

Requirements56%

Page 5: Object Oriented Development with UML Requirements with Use ... · What are the main sources of bugs? (source: "Software Testing", Ron Patton) Bugs . เกิดขึ้นได้จากหลาย

Distribution of Effort to Fix Bugs

Code1%

Other4% Design

13%Requirements82%

Page 6: Object Oriented Development with UML Requirements with Use ... · What are the main sources of bugs? (source: "Software Testing", Ron Patton) Bugs . เกิดขึ้นได้จากหลาย

Reasons Projects Fail

Project Challenged Factors % of Responses

1. Lack of User Input 12.8%

2. Incomplete Requirements & Specifications 12.3%

3. Changing Requirements & Specifications 11.8%

4. Lack of Executive Support 7.5%

5. Technology Incompetence 7.0%

6. Lack of Resources 6.4%

7. Unrealistic Expectations 5.9%

8. Unclear Objectives 5.3%

9. Unrealistic Time Frames 4.3%

10. New Technology 3.7%

Other 23.0%

The Chaos Report Standish Group 94

Page 7: Object Oriented Development with UML Requirements with Use ... · What are the main sources of bugs? (source: "Software Testing", Ron Patton) Bugs . เกิดขึ้นได้จากหลาย

What Is a Requirement ?

IEEE Standard Glossary of Software Engineering Terminology:

เปนเงอนไขหรอความสามารถทตองการของผใชในการแกไขปญหา

เพอใหเปนไปตามวตถประสงคทกาหนดไว

requirements เปนการระบวาอะไรทตองการพฒนา ใชแสดงถง "what" ไมใช "how“

Page 8: Object Oriented Development with UML Requirements with Use ... · What are the main sources of bugs? (source: "Software Testing", Ron Patton) Bugs . เกิดขึ้นได้จากหลาย

Requirements

ไมมความตองการของระบบใดทเหมอนกน อยางไรกตามมกระบวนการหลาย

อยางทชวยในการคนหาและกาหนดความตองการของระบบ เชน

วตถประสงค ขนาด และความซบซอนของระบบ เปนตน

Page 9: Object Oriented Development with UML Requirements with Use ... · What are the main sources of bugs? (source: "Software Testing", Ron Patton) Bugs . เกิดขึ้นได้จากหลาย

Functional Requirements

ความตองการทเปนฟงกชนการทางาน (Function Requirements) เปนสงท

ระบบควรตองทาหรอเปนหนาทหลกของระบบ ความตองการแบบนถอเปน

บรการทซอฟตแวรควรมนนเอง

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

ตาง ๆ ทเกยวของกบผปฏบตงาน

เทคนคในการนาเสนอ

Use cases,

Requirements List—“Shall” statements,

Page 10: Object Oriented Development with UML Requirements with Use ... · What are the main sources of bugs? (source: "Software Testing", Ron Patton) Bugs . เกิดขึ้นได้จากหลาย

Non-Functional Requirements

ความตองการทไมไดเปนฟงกชนการทางาน (Non-Function Requirements) จะ

ไมเกยวของโดยตรงกบงานหรอฟงกชนหลก เชน

ความสามารถในการใชงาน (Usability) Human Factors, Help,

Documentation

ประสทธภาพของระบบ ไดแก Response Times, Throughput, Resource

Usage

ความนาเชอถอของระบบ (Reliability) ไดแก Failure Rates,

Recoverability, Availability

ความสะดวกในการเคลอนยายไปยงสภาพแวดลอมใหม (Portability)

การสนบสนนดานตาง ๆ เชน Maintainability, Internationalization

Page 11: Object Oriented Development with UML Requirements with Use ... · What are the main sources of bugs? (source: "Software Testing", Ron Patton) Bugs . เกิดขึ้นได้จากหลาย

Use Cases Modeling

อาศยแนวคดทวา “อะไรคอสงทระบบตองทาสาหรบผใชแตละคน”

ยสเคสไดอาแกรมเปนเทคนคในการพฒนาแบบหนงทถกรวบรวมไวใน

UML ถกคดคนโดย Ivar Jacobson ในป 1994

ชวยในการคนหาความตองการของระบบตามมมมองของผใช

ใชสาหรบการตรวจสอบตดตามการเปลยนความตองการของระบบตาม

ฟงกชนการทางานและการทางานจรงทเกดขนภายในระบบ

ใชเปนกลไกสาหรบขบเคลอนการดาเนนการของการพฒนาระบบ

เปนเครองมอทใชในการคนหาคลาส

ใชเปนพนฐานในการทดสอบระบบ

ใชเปนพนฐานสาหรบการประเมนราคาของซอฟตแวร

Page 12: Object Oriented Development with UML Requirements with Use ... · What are the main sources of bugs? (source: "Software Testing", Ron Patton) Bugs . เกิดขึ้นได้จากหลาย

ระบทก ๆ actors ทเปนผใชระบบ

กาหนด Use cases ของระบบ

กาหนดความสมพนธระหวาง actors และความสมพนธระหวาง Use cases

สราง Use case Diagram ในระดบบนสด

เพมเตมรายละเอยดของ Use case Diagram ทแสดงถงขอบเขตของระบบ

กาหนดรายละเอยดของแตละ Use case

Development of New Use case Template

Page 13: Object Oriented Development with UML Requirements with Use ... · What are the main sources of bugs? (source: "Software Testing", Ron Patton) Bugs . เกิดขึ้นได้จากหลาย

Graphical Notation

สญลกษณของ actor ถกนาเสนอโดย stick man โดยมการระบชอของ actor

ไวดานลางในรปของ role เปนหลก

สญลกษณของ use case ถกนาเสนอโดย ellipse ทมการระบชอของยสเคส

ไวภายใน

Use Case

Actor

Page 14: Object Oriented Development with UML Requirements with Use ... · What are the main sources of bugs? (source: "Software Testing", Ron Patton) Bugs . เกิดขึ้นได้จากหลาย

What is an Actor ?

ใชสาหรบการนาเสนอสงทตองการตดตอกบระบบ [Jacobson ‘92]

นาเสนอบทบาท (Role) ของสงทอยภายนอกระบบ เชน ผใช ฮารดแวร หรอ

ระบบอน ๆ ทมการตดตอกบระบบทตองการพฒนา (อยภายนอกระบบ)

Actor สอสารกบระบบโดยการตดตอกนผานการสงหรอรบแมสเสจระหวางกน

แตละยสเคสจะไมถกจากดอยกบหนง Actor

Jacobson (1992) ไดจาแนก Actor ออกเปนสองชนด:

Primary Actor: เปนผทไดรบประโยชนโดยตรงจากระบบ (ถกกาหนดไวดาน

ซายมอของยสเคสไดอาแกรมเสมอ)

Secondary Actor: เปนผทใหบรการหรอใหการสนบสนน actor อน (ขวามอ)

Secondary Actor ไมสามารถเกดขนไดโดยปราศจาก Primary Actor

Page 15: Object Oriented Development with UML Requirements with Use ... · What are the main sources of bugs? (source: "Software Testing", Ron Patton) Bugs . เกิดขึ้นได้จากหลาย

Actor Personalities

Actor

Initiator: ทาหนาทกระตนใหเกดการทางานของยสเคส

External Server: ทาหนาทใหบรการกบระบบผานการทางานภายในยสเคส

Receiver: ทาหนาทในการรบขอมลจากยสเคสเพยงอยางเดยว

Facilitator: ทาหนาทสนบสนนการตดตอกบระบบของ actor อน

คณสมบตของ actor

Actor อาจใชไดกบหลาย ๆ Use Cases

Use Case อาจตดตอไดกบหลาย ๆ Actors

การตดตอกนสามารถนาเสนอผานสญลกษณเสนตรงได

Page 16: Object Oriented Development with UML Requirements with Use ... · What are the main sources of bugs? (source: "Software Testing", Ron Patton) Bugs . เกิดขึ้นได้จากหลาย

Relationship between Actor

เนองจาก Actor คอคลาส ดงนนจงสามารถมความสมพนธกนไดเชนเดยวกบ

คลาส แตสาหรบใน Use Case ไดอาแกรมความสมพนธทถกระบไวเพยงอยาง

เดยว คอ Generalization เพอใชสาหรบแสดงการโตตอบระหวาง Actor

จานวนหนงเทานน

Generalization จะเกดขนเมอบทบาทของ Actor จะถกกาหนดใหอยในรปของ

Actor Super-class ซงจะมลกษณะเปนการสบทอดจาก Actor นนเอง

Officer

Loan Officer

Page 17: Object Oriented Development with UML Requirements with Use ... · What are the main sources of bugs? (source: "Software Testing", Ron Patton) Bugs . เกิดขึ้นได้จากหลาย

Use Cases

Jacobson (1992):Use case เปนลาดบของ transaction ทถกดาเนนการโดย

ระบบ ซงใหผลลพธทชดเจนแก actor หนง ๆ

Use Case ถกกาหนดในรปจานวนและลาดบการกระทาทเกดขนในระบบ

คณลกษณะของ Use Case

Use Case จะเกดขนจากการกระทาของ Actor เสมอ ทงทางตรงหรอ

ทางออมเพอใหระบบทางานตาม Use case ทปรากฏ

Use Case ตองใหผลลพธกบ Actor ไมวาจะเปนทางใดทางหนงเสมอ

Use Case ตองมความสมบรณในตว โดยไมตองมการแยกรายละเอยด

ใหลกลงไปในระดบถดไป

use-case name

Page 18: Object Oriented Development with UML Requirements with Use ... · What are the main sources of bugs? (source: "Software Testing", Ron Patton) Bugs . เกิดขึ้นได้จากหลาย

Use Case Names

การกาหนดชอยสเคสจะใชรปแบบดงตอไปน:

คากรยา + คานามในรปของออปเจค เชน สงซอ (Place order) รองขอบรการ (Request service) เปนตน

ระมดระวงการใชคากรยาทมความหมายคลมเครอ

เชน ทา (do) หรอ กระบวนการ (process)

ใชคากรยาทมความหมายชดเจนไดทนท

เชน เขาสระบบ (Login) คนหา (search) อนมต (approve) แจงใหทราบ (notify) เปนตน

ใชคาประเภท active voice ไมใช passive

ควรเลอกใชชอตามมมมองของผใชไมใชตวมมมองของระบบ

Page 19: Object Oriented Development with UML Requirements with Use ... · What are the main sources of bugs? (source: "Software Testing", Ron Patton) Bugs . เกิดขึ้นได้จากหลาย

Use Case Names: Example

Excellent - Purchase Concert Ticket

Very Good - Purchase Concert Tickets

Good - Purchase Ticket (แตขาดรายละเอยดทจาเปน)

Fair - Ticket Purchase (ถอเปน passive)

Poor - Ticket Order (ใชมมมองของระบบ ไมใชมมมองผใช)

Unacceptable - Pay for Ticket (เปน procedure ไมใช process)

ตวอยางชอของ use case ทไมเหมาะสม ไดแก CRUD

C - actor Creates data

R - actor Retrieves data

ทงหมดถอเปน procedural และไมไดแสดงใหเหนถงสงทผใชตองการ

U - actor Updates data

D - actor Deletes data

Page 20: Object Oriented Development with UML Requirements with Use ... · What are the main sources of bugs? (source: "Software Testing", Ron Patton) Bugs . เกิดขึ้นได้จากหลาย

How Actors and Use Cases Interact

สญลกษณเสนตรงทลากระหวาง actor กบ use case ใชเพอแสดงใหเหนวา

actor มการตดตอกบ use case สวนหวลกศรใชในการกาหนดทศทางและ

ความสมพนธระหวาง actor และ use case

ทศทางความสมพนธโดยปกตจะเปนสองทศทาง

กาหนดความสมพนธระหวางแตละ actor และ-use-case

กาหนดรายละเอยดอยางยอสาหรบความสมพนธระหวางกน

actor

use case

Both actor and use case can initiate the communication.

actoruse case

The use case initiatethe communication.

Page 21: Object Oriented Development with UML Requirements with Use ... · What are the main sources of bugs? (source: "Software Testing", Ron Patton) Bugs . เกิดขึ้นได้จากหลาย

Relationship between Use Case

Use Case หนง ๆ อาจมการใชงานรวมกบ Use Case อน ๆ ซงลกษณะดงกลาวเรยกวาความสมพนธระหวางยสเคส

ความสมพนธระหวางยสเคส ไดแก Extends, Includes/Uses และGeneralization

ความสมพนธระหวางยสเคสชวยลดความซ าซอนของงาน ตลอดจนความขดแยงตาง ๆ ภายในแตละยสเคส

การกาหนดความสมพนธควรทาในมมมองของวธการเชงวตถมากกวาการใชวธการแบบ functional decomposition

Page 22: Object Oriented Development with UML Requirements with Use ... · What are the main sources of bugs? (source: "Software Testing", Ron Patton) Bugs . เกิดขึ้นได้จากหลาย

Relationship: Generalization

เกดขนเมอ Use case จานวนหนงมพฤตกรรมบางสวนทเหมอนกน พฤตกรรม

ดงกลาวจะถกนามากาหนดใหอยในรปของ Use case หนง ๆ ทสามารถ

นาไปใชไดโดย Use case อน ๆ ทมพฤตกรรมบางสวนทเหมอนกน

เชนในกรณของการ make payment ซงอาจมการสบทอดไปยง use case ทเปน

Pay Cash หรอ Pay by Credit Card นนคอ use case สบทอดทงหมดจะตองถก

ใชรวมกบ Use case หลกในการทางานเสมอ

Make Payment

Pay by Credit Card Pay by Cash

Page 23: Object Oriented Development with UML Requirements with Use ... · What are the main sources of bugs? (source: "Software Testing", Ron Patton) Bugs . เกิดขึ้นได้จากหลาย

Relationship: Include

use case ทมความสมพนธแบบ include จะตองทางานรวมกบ Use case ทถก

กาหนดไวเสมอ

ใน UML รนแรก ๆ จะเรยกความสมพนธแบบนวา use

ความสมพนธแบบน use case ยอยจะถกประมวลผลโดยเปนสวนหนงของ

use case หลก นนคอการทางานของ use case หลกจะไมสมบรณ หากไมม

การประมวลผล use case ยอย

User

does Something Does portion of something

<<include>>

Page 24: Object Oriented Development with UML Requirements with Use ... · What are the main sources of bugs? (source: "Software Testing", Ron Patton) Bugs . เกิดขึ้นได้จากหลาย

Use Case Relationship: Include

BorrowBooks

CheckBorrow Limit

Borrower

Check Library Fine

<<include>><<include>>

Find Item by Title

Find Items by Actor

Search MovieDatabase

«include»

«include»Customer

Dependency

Page 25: Object Oriented Development with UML Requirements with Use ... · What are the main sources of bugs? (source: "Software Testing", Ron Patton) Bugs . เกิดขึ้นได้จากหลาย

Relationship: Extend

ความสมพนธแบบ Extend ใชสาหรบการกาหนดพฤตกรรมการทางานท

เปนทางเลอกออกจากพฤตกรรมทเกดขนเปนปกต

การประมวลผล extend use case จะเกดขนในกรณทเปนไปตามเงอนไขท

กาหนดไว มฉะนนการประมวลผลจะเกดขนท Use case หลกเทานน หาก use case B มความสมพนธแบบ extend มาจาก use case A

ภายในuse case ตองมเงอนไขทางลอจกทกาหนดวา

if TRUE --> perform B

User

does SomethingDoes another thing if condition is true

<<Extend>>

Page 26: Object Oriented Development with UML Requirements with Use ... · What are the main sources of bugs? (source: "Software Testing", Ron Patton) Bugs . เกิดขึ้นได้จากหลาย

Extend Relationships

«extend»

Stereotype

Request a book search

Clerk

Borrower

BorrowBooks

Print outLoan Receipt

<<extend>>

Page 27: Object Oriented Development with UML Requirements with Use ... · What are the main sources of bugs? (source: "Software Testing", Ron Patton) Bugs . เกิดขึ้นได้จากหลาย

Finding Actors

คาถามทชวยในการกาหนด Actor

ผใชงานหลกของระบบ (primary actors) คอใคร ?

ผทตองการการสนบสนนการทางานจากระบบคอใคร ?

ผทาหนาทบารงรกษา และบรหารระบบ (secondary actors) คอใคร ?

ฮารดแวรใดทระบบจาเปนตองใช ?

ระบบอนทอยภายนอกตองการตดตอกบระบบ ?

ใครหรอสงใดทสนใจในผลลพธของระบบ ?

Tips

ไมควรพจารณาเฉพาะผทใชงานระบบโดยตรง แต พจารณา users อนๆ

ทตองการใชบรการจากระบบดวย

Page 28: Object Oriented Development with UML Requirements with Use ... · What are the main sources of bugs? (source: "Software Testing", Ron Patton) Bugs . เกิดขึ้นได้จากหลาย

Finding Use Cases

สาหรบแตละ actor ตอบคาถามตอไปน

ฟงกชนการทางานใดท actor ตองการจากระบบ ?

actor จาเปนตองสราง อาน ลบ แกไข หรอเกบขอมลภายในระบบหรอไม ?

เหตการณใดบางทระบบตองแจงให actor ทราบหรอ actor ตองแจงให

ระบบทราบ ?

ฟงกชนการทางานของระบบ ชวยทาใหงานประจาวนของ actor งายขน

หรอไม ?

Page 29: Object Oriented Development with UML Requirements with Use ... · What are the main sources of bugs? (source: "Software Testing", Ron Patton) Bugs . เกิดขึ้นได้จากหลาย

Correct

Take Picture

Change Film

Photographer

Open Shutter

FlashPhotographer

Close Shutter

Incorrect

How do you know what to put in the "System" box?

จากไดอาแกรมในลาดบถดไปจะเปนการนาเสนอ use case สาหรบการ

ถายรป

Page 30: Object Oriented Development with UML Requirements with Use ... · What are the main sources of bugs? (source: "Software Testing", Ron Patton) Bugs . เกิดขึ้นได้จากหลาย

Examples: Ski resort information system

Users should be able to query weather and snow condition forecasts for a

date they enter.

The system should allow to book single or double rooms at the resort hotel

“Skier’s Luck” online (with credit card).

Visitors should be able to book one-day beginners courses on snowboards.

There is only one course a day.

The max. size of a course is 8 persons.

The resort offers special courses for kids. In order to built courses with

kids of same age, the customer has to enter the kid’s age.

Canceling of course or room bookings are only possible up to 10 days

ahead.

Page 31: Object Oriented Development with UML Requirements with Use ... · What are the main sources of bugs? (source: "Software Testing", Ron Patton) Bugs . เกิดขึ้นได้จากหลาย

Examples: Ski resort information system

Users จะตองสามารถตรวจสอบสภาพอากาศและหมะลวงหนาสาหรบ

วนทเขาพกได

ระบบจะยอมใหจองหองเดยวหรอหองคของรสอรท “Skier’s Luck” แบบ

online โดยใช credit card

ผเขาพกสามารถจองชนเรยน snowboards แบบ 1 วนสาหรบผเรมตนได

ชนเรยนจะเปนแบบ 1 course ตอวน

จานวนผเรยนไมเกน 8 persons ตอชน

รสอรทจะม courses พเศษสาหรบเดก ในการเขา courses เดกจะตองอาย

เทากน ดงนนผเขาพกจะตองระบอายของเดก

การยกเลกการจองหองพกและ course จะตองแจงลวงหนากอน 10 วน

Page 32: Object Oriented Development with UML Requirements with Use ... · What are the main sources of bugs? (source: "Software Testing", Ron Patton) Bugs . เกิดขึ้นได้จากหลาย

forcast

enter_date<<extend>>

User

book_room

book_courses

beginner snowboard Course

<<extend>>

get_credit_card validate_credit_card

<<extend>>

Single

<<extend>>

Double

<<extend>><<extend>>

check_number_of Days_ahead

get_age_of_child

Check_size_of_courses

<<extend>>cancel_reservation

Children of User

children's courses

<<extend>>

<<extend>>

Page 33: Object Oriented Development with UML Requirements with Use ... · What are the main sources of bugs? (source: "Software Testing", Ron Patton) Bugs . เกิดขึ้นได้จากหลาย

Example Use Case Diagram

Query weather&snow

forecast

Book room

Book kids’ SB course

Visitor

Cancel course

Book SB course

Cancel room

Enter personal info

<<extend>>

<<include>>

<<include>>

Page 34: Object Oriented Development with UML Requirements with Use ... · What are the main sources of bugs? (source: "Software Testing", Ron Patton) Bugs . เกิดขึ้นได้จากหลาย

Case Study: Video Rental System

1. รานเชาวดโอแหงหนงเปดใหบรการเชาหนงทงแบบซดและดวด

2. นอกจากนนยงใหเชาเกมส

3. หนงและเกมสใดทไดรบความนยมจะถกจดเกบไวเปนจานวนหลายชด

4. พนกงานสามารถระบไดวารายการสนคาใดทมอยในราน โดยการคนหาจากชอ

เรอง

5. พนกงานจะตองสามารถพมพรายชอของหนงและเกมสทอยในรานได

6. พนกงานจะตองสามารถตรวจสอบลกคาได เฉพาะลกคาทลงทะเบยนแลว

เทานนจงสามารถยมรายการสนคาตาง ๆ ได พนกงานจะตองสามารถระบไดวา

ลกคารายใดทมการยมรายการสนคาและจานวนครงทยมได

7. หลงจากการยมรายการสนคาออกไป ลกคาจะตองคนภายใน 3 วน

Page 35: Object Oriented Development with UML Requirements with Use ... · What are the main sources of bugs? (source: "Software Testing", Ron Patton) Bugs . เกิดขึ้นได้จากหลาย

How a user of the system will interact with it

1. รานเชาวดโอแหงหนงเปดใหบรการเชาหนงทงแบบซดและดวด

2. นอกจากนนยงใหเชาเกมส

StoreEmployee

rent itemto customer

3. หนงและเกมสใดทไดรบความนยมจะถกจดเกบไวเปนจานวนหลายชด

StoreEmployee

Add an item

Page 36: Object Oriented Development with UML Requirements with Use ... · What are the main sources of bugs? (source: "Software Testing", Ron Patton) Bugs . เกิดขึ้นได้จากหลาย

Case Study: Video Rental System

4. พนกงานสามารถระบไดวารายการสนคาใดทมอยในราน โดยการ

คนหาจากชอเรอง

5. พนกงานจะตองสามารถพมพรายชอของหนงและเกมสทอยในรานได

StoreEmployee

print list

View itemsby title

Page 37: Object Oriented Development with UML Requirements with Use ... · What are the main sources of bugs? (source: "Software Testing", Ron Patton) Bugs . เกิดขึ้นได้จากหลาย

Case Study: Video Rental System

6. พนกงานจะตองสามารถตรวจสอบลกคาได เฉพาะลกคาทลงทะเบยนแลว

เทานนจงสามารถยมรายการสนคาตาง ๆ ได พนกงานจะตองสามารถระบ

ไดวาลกคารายใดทมการยมรายการสนคาและจานวนครงทยมได

7. หลงจากการยมรายการสนคาออกไป ลกคาจะตองคนภายใน 3 วน

StoreEmployee Search for

a customer

Register customer

Return itemfrom customer

Page 38: Object Oriented Development with UML Requirements with Use ... · What are the main sources of bugs? (source: "Software Testing", Ron Patton) Bugs . เกิดขึ้นได้จากหลาย

Use Case Diagram : Video Rental System

StoreEmployee Rent item

to customer

Add an item

Return itemfrom customer

View itemsby title

Print list

Search fora customerRegister

customer

Page 39: Object Oriented Development with UML Requirements with Use ... · What are the main sources of bugs? (source: "Software Testing", Ron Patton) Bugs . เกิดขึ้นได้จากหลาย

Review Video Rental System

StoreEmployee

Rent itemto customer

Register Customer

Return itemfrom customer

View itemsby title

Print list

Search fora customer

Add an Item<<extend>>

<<include>>

Page 40: Object Oriented Development with UML Requirements with Use ... · What are the main sources of bugs? (source: "Software Testing", Ron Patton) Bugs . เกิดขึ้นได้จากหลาย

Use Cases and Scenarios

วธการหนงทไดผลดในการอธบายรายละเอยดของยสเคสไดแก การจดทา

เอกสารทเรยกวา ซนารโอ (scenario)

เปนเอกสารเพอใชสาหรบการนาเสนอลาดบของการตดตอกนระหวางแอค-

เตอรและยสเคส จากจดเรมตนจนเสรจสนสมบรณ

ซนารโอนาเสนอการตดตอระหวางยสเคสกบ

แอคเตอรเปน 2 รปแบบไดแก

Basic Flow: การทางานทเกดขนเปนปกต

Alternative Flow: การทางานทเปน

ทางเลอกเมอมความผดพลาดเกดขน

Page 41: Object Oriented Development with UML Requirements with Use ... · What are the main sources of bugs? (source: "Software Testing", Ron Patton) Bugs . เกิดขึ้นได้จากหลาย

Use Case Scenario Template

Use Case Name :

Actors :DescriptionUse case ReferencedBasic Flow

Alternative Flow

Pre-conditionsPost- conditions

Page 42: Object Oriented Development with UML Requirements with Use ... · What are the main sources of bugs? (source: "Software Testing", Ron Patton) Bugs . เกิดขึ้นได้จากหลาย

Basic Flow

เปนลาดบขนตอนของเหตการณทเกดขนระหวาง Actor กบระบบ

แตละขนตอนประกอบไปดวยกจกรรมทเกยวของกบ input จาก Actor และการ

ตอบสนองจากระบบ

แตละขนตอนควรอยในรป ประธาน + กรยา + กรรม และอยในรปของ present

tense และ active voice

ในระดบของการออกแบบคลาส

ประธาน -> Sender Object

กรยา -> method

กรรม -> Receiver Object

..

......

Class 1 Class 2

Page 43: Object Oriented Development with UML Requirements with Use ... · What are the main sources of bugs? (source: "Software Testing", Ron Patton) Bugs . เกิดขึ้นได้จากหลาย

เปนทางเลอกของการทางานในกรณท Basic Flow มความผดพลาดเกดขน เชน

ทางเลอกในการจดการความผดพลาด

ทางเลอกในการสนสดการทางาน

มลกษณะเปนเงอนไข

แสดงเหตผลสาหรบ alternative flow ในรปเงอนไขทผใชสามารถตรวจสอบได

วธการจดการ

แสดงลาดบการจดการกบความผดพลาดทเกดขนตามรปแบบตอไปน

หมายเลข เงอนไข และการทางานทเกดขน เชน

3.1. ในกรณท [actor] กรอกขอมล [action] ไมถกตอง ระบบจะแสดง

ขอความเตอน …

Alternative Flow

Page 44: Object Oriented Development with UML Requirements with Use ... · What are the main sources of bugs? (source: "Software Testing", Ron Patton) Bugs . เกิดขึ้นได้จากหลาย

ตวอยาง Cash Register

Use Case: การซอสนคา (Buy items)

Actors: Customer, Cashier

Type: Primary

Description: เมอลกคา (Customer) มาทเคานเตอรพรอมกบ

สนคา (items) ทตองการซอ (Purchase)

พนกงานเกบเงน (Cashier) จะบนทกรายการ

สงซอ (purchase items) และทาหนาทเกบเงน (

collects payment) ไปพรอมกน เมอเสรจสน

ขนตอนดงกลาวแลว ลกคา ( Customer) จะ

ออกไปพรอมกบสนคา ( items) ทตองการ

Page 45: Object Oriented Development with UML Requirements with Use ... · What are the main sources of bugs? (source: "Software Testing", Ron Patton) Bugs . เกิดขึ้นได้จากหลาย

A simple use case diagram

Customer

Buy Items with Cash

Cashier

Page 46: Object Oriented Development with UML Requirements with Use ... · What are the main sources of bugs? (source: "Software Testing", Ron Patton) Bugs . เกิดขึ้นได้จากหลาย

Use Case Scenario : Header

เมอลกคา (Customer) มาทเคานเตอรพรอมกบสนคา (items) ทตองการซอ (Purchase) พนกงาน(Cashier) บนทกรายการสงซอ (purchase items) และทาหนาทเกบเงน ( collects payment) ไปพรอมกน เมอเสรจสนขนตอนดงกลาวแลวลกคา ( Customer) จะออกไปพรอมกบสนคา ( items)

Use Case: การซอสนคาดวยเงนสด (Buy Items with Cash)

Actors: Customer (Primary Actor), Cashier (Secondary Actor)

Purpose: แสดงลาดบเหตการณในการซอสนคาดวยเงนสด

Description:

Basic Flow:

Page 47: Object Oriented Development with UML Requirements with Use ... · What are the main sources of bugs? (source: "Software Testing", Ron Patton) Bugs . เกิดขึ้นได้จากหลาย

Use Case Scenario : Basic Flow

Basic Flow : 1. พนกงานปอนรหสสนคาทลกคาเลอกไว

2. ระบบรบคารหสสนคา

3. ระบบคนหารายละเอยดสนคาจากรหส

4. ระบบแสดงราคาตอหนวยของสนคา

5. พนกงานปอนจานวนหนวยของสนคา

6. กรณทมสนคามากกวา 1 รายการ พนกงานทาซ าขนตอนท

1 – 5 จนครบจานวนรายการ

7. พนกงานบนทกรายการสงซอ

8. ระบบรบคาและบนทกขอมล

9. ระบบคานวณและแสดงคาใชจายทงหมดของการสงซอ

10. ระบบพมพใบเสรจใหแกลกคา

หมายเหต : ยสเคสนไมรวมขนตอนการจายเงน

Page 48: Object Oriented Development with UML Requirements with Use ... · What are the main sources of bugs? (source: "Software Testing", Ron Patton) Bugs . เกิดขึ้นได้จากหลาย

Use Case Scenario : Alternate Flow

Alternative

Flow :1.1 หากพนกงานปอนรหสสนคาผดพลาด สามารถแกไขได

โดยเลอกรายการแกไข

PreCondition

PostCondition สนคาซอแลวไมสามารถคนหรอเปลยนได

การสงซอเรมตนและสนสดสาหรบลกคาแตละราย

5.1 หากพนกงานปอนจานวนสนคาผดพลาด สามารถแกไข

ไดโดยเลอกรายการแกไข

Page 49: Object Oriented Development with UML Requirements with Use ... · What are the main sources of bugs? (source: "Software Testing", Ron Patton) Bugs . เกิดขึ้นได้จากหลาย

Alternative Use Cases

ในทางทฤษฎอาจมทางเลอกในการทางานแบบ alternatives ไดหลายวธ ดงในการสรางแบบจาลองยสเคส อาจมการนาเสนอ Alternative Use Cases

ใชสาหรบการนาเสนอลาดบของเหตการณทอยในรปของ trigger เชนในกรณทม exceptions เกดขนในยสเคส

Alternative Use Case จะทางานรวมกบ Use Case หลกเสมอ

AlternativeUse Cases

Base Use Case

UC 101

UC 101-A1

UC 101-A2

Page 50: Object Oriented Development with UML Requirements with Use ... · What are the main sources of bugs? (source: "Software Testing", Ron Patton) Bugs . เกิดขึ้นได้จากหลาย

Use Case Diagram : Recommendation

ขนตอนท 1: กาหนดวาใครคอผใชระบบ

ขนตอนท 2: กาหนดยสเคสอาจใชขอมลจากความตองการของระบบโดยอาศย

มมมองของแอคเตอรเปนหลก

ขนตอนท 3: กาหนดความสมพนธระหวางยสเคส

ขนตอนท 4: สราง Use Case Scenario เพออธบายการทางานแบบ Basic Flow

ขนตอนท 5: อธบายการทางานแบบ Alternative Flow

ขนตอนท 6 : ทบทวนรายละเอยดการทางานของแตละยสเคส หากมขนตอน

การทางานหรอความซบซอนเกดขนมากเกนไปควรพจารณาแยกยสเคส

ดงกลาวออกเปนยสเคสยอย ๆ จานวน use case ทเหมาะสมไมควรเกน 7 +- 1

ขนตอนท 7 : พจารณาทาซ าในขนตอนท 2 - 6 สาหรบแตละแอคเตอร

Page 51: Object Oriented Development with UML Requirements with Use ... · What are the main sources of bugs? (source: "Software Testing", Ron Patton) Bugs . เกิดขึ้นได้จากหลาย

Use Case Checklist

รายละเอยดโดยยอแสดงใหเหนภาพการทางานของยสเคสหรอไม

แตละยสเคสทกาหนดไวตองมความสมบรณในตว

แตละยสเคสจะตองเกยวของกบอยางนอย 1 actor

แตละยสเคสมความเปนอสระจากยสเคสอน ๆ หรอไม

บางสวนของเหตการณทไดถกกาหนดไวแลวในยสเคสอน(include relationship)

บางสวนของเหตการณทถกกาหนดไวแลว โดยเปนสวนประกอบของยสเคสอน

(extends relationship)

ยสเคสใดทมพฤตกรรมการทางานคลายกนหรอไม (generalize relationship)

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

ชอของยสเคสสอความหมายใหเหนพฤตกรรมการทางานไดชดเจน โดยผใชระบบ

สามารถเขาไดโดยไมตองการคาอธบายเพมเตม

Page 52: Object Oriented Development with UML Requirements with Use ... · What are the main sources of bugs? (source: "Software Testing", Ron Patton) Bugs . เกิดขึ้นได้จากหลาย

Quality Checklist

Correctness : ทก ๆ ยสเคสไดแสดงใหเหนถงความตองการในสวนทเปนฟงกชน

การทางานของระบบอยางถกตองและชดเจนหรอไม

Completeness : ยสเคสตาง ๆ ครอบคลมทก ๆ ฟงกชนการทางานของระบบ

หรอไม

Clarity : ยสเคสถกกาหนดไวอยางชดเจน โดยไมกอใหเกดความสบสน หรอตอง

ตความ ศพททใชในการกาหนด Actor และเหตการณทเกดขนตองชดเจน รวมถง

การกาหนดนยามศพท

Modifiability : โครงสรางและสไตลของยสเคสทสนบสนนการเปลยนแปลงแกไข

ทเกดขนหรอไม

Page 53: Object Oriented Development with UML Requirements with Use ... · What are the main sources of bugs? (source: "Software Testing", Ron Patton) Bugs . เกิดขึ้นได้จากหลาย

Use Case Quality Checklist

Consistency : ยสเคสตาง ๆ ตองมความสอดคลองกน และตองไมมเหตการณภายในแตละยสเคสทมความขดแยงกน Actor และเหตการณทเกดขนจะตองถก

กาหนดไว และมการใชงานสอดคลองกนในทก ๆ ยสเคส

ยสเคสตองสอดคลองกบสวนประกอบของ OOAD อน เชน คลาส สเตท ไดอา

แกรม เปนตน

Verifiability : มกระบวนการตรวจสอบวาซอฟตแวรเปนไปตามความตองการของระบบทถกระบโดยยสเคสหรอไม ขอกาหนดตาง ๆ สามารถทดสอบไดหรอไม

Traceability : ยสเคสสนบการตรวจสอบตดตามทง backward และ forward หรอไม (ตงแตความตองการทางธรกจไปจนถงไดอาแกรมและขอกาหนดตาง ๆ ในการออกแบบระบบ)

Page 54: Object Oriented Development with UML Requirements with Use ... · What are the main sources of bugs? (source: "Software Testing", Ron Patton) Bugs . เกิดขึ้นได้จากหลาย

Development of the Use Case Model

Iteration 1Obvious use cases.Simple use case descriptions.

Iteration 2 Additional use cases.Simple use case descriptions.Prototypes.

Iteration 3Structured use cases.Structured use case descriptions.Prototypes.

Assign staff to work on

a campaign

Campaign Manager

Add a new advert to

a campaign

Check campaign budget

Find campaign

Accountant

summary Print campaign

invoice

«include»

«extend» «extend»

Print campaign

«include»

«include»

Campaign Management

Assign staff to work on

a campaign

Campaign Manager

Add a new advert to

a campaign

Check campaign budget

Find campaign

Accountant

summary Print campaign

invoice

«include»

«extend» «extend»

Print campaign

«include»

«include»

Campaign Management

Calculate staff bonuses

Accountant

Add a new staff member

Add a new staff grade

Change the rate for a

staff grade

Change the grade for a

staff member

Staff Management

Calculate staff bonuses

Accountant

Add a new staff member

Add a new staff grade

Change the rate for a

staff grade

Change the grade for a

staff member

Staff Management

Calculate staff bonuses

Accountant

Add a new staff member

Add a new staff grade

Change the rate for a

staff grade

Change the grade for a

staff member

Staff Management

Calculate staff bonuses

Accountant

Add a new staff member

Add a new staff grade

Change the rate for a

staff grade

Change the grade for a

staff member

Staff Management

Calculate staff bonuses

Accountant

Add a new staff member

Add a new staff grade

Change the rate for a

staff grade

Change the grade for a

staff member

Staff Management

Assign staff to work on

a campaign

Campaign Manager

Add a new advert to

a campaign

Check campaign budget

Find campaign

Accountant

summary Print campaign

invoice

«include»

«extend» «extend»

Print campaign

«include»

«include»

Campaign Management

Spring Jewellery Campaign 1997Spring Jewellery Campaign 2001Spring Jewellery Campaign 2002Summer Collection 1998

OK Quit

Campaign:

Campaign Selection

Holborn MotorsLynch PropertiesYellow Partridge Zeta Systems

Client:

Yellow Partridge

Spring Jewellery Campaign 1997Spring Jewellery Campaign 2001Spring Jewellery Campaign 2002Summer Collection 1998

OK Quit

Campaign:

Campaign Selection

Holborn MotorsLynch PropertiesYellow Partridge Zeta Systems

Client:

Yellow Partridge

Spring Jewellery Campaign 2002

OK Quit

Campaign:

Campaign Selection

Holborn MotorsLynch PropertiesYellow Partridge Zeta Systems

Client:

Spring Jewellery Campaign 1997Spring Jewellery Campaign 2001Spring Jewellery Campaign 2002Summer Collection 1998

OK Quit

Campaign:

Campaign Selection

Holborn MotorsLynch PropertiesYellow Partridge Zeta Systems

Client:

Yellow Partridge

Spring Jewellery Campaign 1997Spring Jewellery Campaign 2001Spring Jewellery Campaign 2002Summer Collection 1998

OK Quit

Campaign:

Campaign Selection

Holborn MotorsLynch PropertiesYellow Partridge Zeta Systems

Client:

Yellow Partridge

Spring Jewellery Campaign 2002

OK Quit

Campaign:

Campaign Selection

Holborn MotorsLynch PropertiesYellow Partridge Zeta Systems

Client:

Page 55: Object Oriented Development with UML Requirements with Use ... · What are the main sources of bugs? (source: "Software Testing", Ron Patton) Bugs . เกิดขึ้นได้จากหลาย

Use Case Tips and Tricks

จานวนยสเคสทเหมาะสม

Cockburn: เทากบจานวน goals ทระบบมอย

Anderson and Fertig: ไมเกน 80 ยสเคสตอระบบงานหนง ๆ

ขนาดยสเคสทเหมาะสม

มการทางานไมเกน 10 ขนตอน (ไมนบขอแรกและขอสดทาย)

ยสเคสทไมเหมาะสม

ยสเคสทไมมผใช (เชน ในกรณของ clock-triggered)

ระบบทมจานวนผใชนอย และมการรนโปรเซสเปนระยะเวลานาน ๆ เชน

ระบบทเนนอลกอลทมส เชน การคานวณทางคณตศาสตรทซบซอน

เปนระบบควบคมทมการทางานแบบตอเนอง เชน ในงานอตสาหกรรม

Page 56: Object Oriented Development with UML Requirements with Use ... · What are the main sources of bugs? (source: "Software Testing", Ron Patton) Bugs . เกิดขึ้นได้จากหลาย

Basic & Alternate Flow

การเขยน Basic Flow ทถกตองและสมบรณประกอบไปดวย 4 ขนตอน:

1. Primary Actor สง request และขอมลเขาสระบบ

2. ระบบมการทวนสอบ (validate) request และขอมลดงกลาว

3. ระบบมการดาเนนการบางอยางโดยการแปลงคาสถานะภายใน

4. ระบบสงผลลพธกลบไปยง actor

Alternate Flow

ลาดบตวเลขตองตรงกบ Basic Flow ทอาจมการจดการ Exception ทเกดขนตวอยางเชน

3.1. ในกรณท [actor] กรอกขอมล [action] ไมถกตอง ระบบจะแสดง

ขอความเตอน …

Page 57: Object Oriented Development with UML Requirements with Use ... · What are the main sources of bugs? (source: "Software Testing", Ron Patton) Bugs . เกิดขึ้นได้จากหลาย

Login

Actors: Trainee, Admin

Basic Flow: 1 - ยสเคสเรมตนเมอผใชเลอกฟงกชน Login

2 - ผใชกรอกชอผใช และรหสผานลงในฟอรมลอกอน

3 - ระบบตรวจสอบความถกตองของขอมลจากสครปต

4 - ระบบรบคาลอกอนจากผใช

5 – ระบบคนหาขอมลลอกอนภายในฐานขอมล

6 – ระบบคนคาสถานะขอมลลอกอนจากการคนหา

7 - ระบบตรวจสอบสถานะการคนคาขอมลลอกอน

8 - ระบบยอมใหผใชเขาสหนาจอหลกเพอทางานในขนตอนตอไป

9 – ยสเคสสนสดการทางาน

Alternate Flow: 3.1 - ในกรณทผใชกรอกขอมลไมครบถวนระบบจะแสดงขอความ “กรณากรอก

ขอมลใหครบ”

7.1- ในกรณทการตรวจสอบชอผใชและรหสผานไมถกตองระบบจะแสดงขอความ

“ไมพบขอมลผใช กรณาตรวจสอบอกครง” และกลบสหนาจอลอกอน

Pre Condition: ผใชตองผานการลงทะเบยนกอนเสมอ

Page 58: Object Oriented Development with UML Requirements with Use ... · What are the main sources of bugs? (source: "Software Testing", Ron Patton) Bugs . เกิดขึ้นได้จากหลาย

Training Registration System

Edit Register Profile

List All Register

iReportPrint Register Profile

Update Payment Status<<include>>

Remove Invalid Register

<<include>>Admin

Fill Register Profile

Login

<<extend>>

Trainee

View General InformationUser

Print All By Criteria

<<include>>

<<extend>>

List Register Detail

List Payment Register

<<extend>>

Page 59: Object Oriented Development with UML Requirements with Use ... · What are the main sources of bugs? (source: "Software Testing", Ron Patton) Bugs . เกิดขึ้นได้จากหลาย

Training Registration System

View General Information : ผใชทวไปเขาดขอมลตาง ๆ ของระบบ ไดแก

รายละเอยดการอบรม ขนตอนการลงทะเบยน และวธการชาระเงน เปนตน

Fill Register Profile : ผใชทวไปกรอกขอมลรายละเอยดสวนตวทงหมดเพอเขารบ

การอบรมตามหลกสตรทกาหนดไว

Login : ผเขาอบรมหรอผดแลระบบกรอกขอมลชอผใชและรหสผานเพอลอกอน

เขาสระบบ ในสวนของผเขาอบรมเพอแกไขขอมลสวนตว (Edit Register

Profile) พมพใบสมคร(Print Register Profile) สวนผดแลระบบลอกอนเพอลบ

ขอมลลงทะเบยนทไมถกตอง(Remove Invalid Register) อพเดทสถานะการชาระ

เงนของผเขาอบรม (Update Payment Status ) แสดงรายชอผเขาอบรมทงหมด

(List All Register) แสดงรายชอผเขาอบรมเปนรายบคคล (List Trainee's Detail)

ตลอดจนพมพรายชอผเขาอบรมทงหมด

Page 60: Object Oriented Development with UML Requirements with Use ... · What are the main sources of bugs? (source: "Software Testing", Ron Patton) Bugs . เกิดขึ้นได้จากหลาย

List Register Detail : ผเขาอบรมสามารถเขาดขอมลรายละเอยดสวนตวไดทนท

หลงจากกรอกขอมลลงทะเบยนเรยบรอยแลว หรออาจลอกอนเขาสระบบเพอ

เลอกดขอมลไดในภายหลง

Edit Register Profile : ผเขาอบรมสามารถแกไขรายละเอยดสวนตวไดทนท

หลงจากกรอกขอมลลงทะเบยนเรยบรอยแลว หรออาจลอกอนเขาสระบบเพอ

เลอกแกไขขอมลไดในภายหลง

Print Register Profile : หลงจากกรอกขอมลลงทะเบยนเรยบรอยแลว ผเขาอบรม

สามารถพมพใบลงทะเบยนไดทนท หรออาจลอกอนเขาสระบบเพอเลอกพมพใบ

ลงทะเบยนไดในภายหลง

List All Register : ระบบจะแสดงรายชอและรายละเอยดทจาเปนของผเขาอบรม

ทงหมด ภายหลงจากการลอกอนของผดแลระบบ

Training Registration System

Page 61: Object Oriented Development with UML Requirements with Use ... · What are the main sources of bugs? (source: "Software Testing", Ron Patton) Bugs . เกิดขึ้นได้จากหลาย

List Trainee's Detail : ผดแลระบบสามารถเลอกดขอมลการลงทะเบยนของ

ผสมครเปนรายบคคลได

Update Payment Status : ผดแลระบบสามารถแกไขสถานะการชาระเงนของผเขา

อบรม เมอเสรจสนขนตอนนถอวาการลงทะเบยนของผเขาอบรมเสรจสมบรณ

Remove Invalid Register : ผดแลระบบสามารถลบขอมลการลงทะเบยนทไม

ถกตองออกจากระบบ

Print All By Criteria : ผดแลระบบสามารถพมพรายชอและรายละเอยดทจาเปน

ของผเขาอบรมทงหมด ตามเงอนไขทกาหนด

Training Registration System

Page 62: Object Oriented Development with UML Requirements with Use ... · What are the main sources of bugs? (source: "Software Testing", Ron Patton) Bugs . เกิดขึ้นได้จากหลาย

Exercise

จงออกแบบยสเคสไดอาแกรมของการไปชมภาพยนตร โดยการซอตวหนาโรง

ยสเคสไดอาแกรมจะตองประกอบไปดวย :

Actor

Use case

Relationship

การเขยน Scenario กาหนดให

เฉพาะขนตอนทเปน Basic Flow เทานน