目錄表

國立屏東大學 資訊工程學系 物件導向軟體工程

5. 需求分析


需求是「該被開發出來的規格」,因此需求最終必須導出規格(Specification)。規格即為軟體系統開發的指引(guideline),在後續系統設計與開發的過程中都必須遵循。需求工程( Requirements Engineering )是描繪出系統該有哪些功能的抽象層次規格並區分出其優先次序的工作,會出現在專案啟始和細部評估階段。需求不完整以及缺少使用者參與是導致專案失敗最主要的兩個原因,兩者的起因都是因為需求工程失敗所導致的。由於軟體系統之成敗取決於需求之滿足,良好的需求工程便成為軟體開發專案是否成功的重要關鍵。通常,需求工程包含需求擷取與需求分析兩大工作項目。

5.1 需求擷取

要瞭解需求必須從資料的搜集開始,由於資料的搜集主要是針對既有的系統或運作方式、流程等著手,所以這一部分的工作又稱為領域分析。

5.1.1 領域分析與領域知識

5.1.2 需求擷取的方式

在擷取使用者需求之前,必須瞭解系統之潛在使用者及可能之人機互動。需求擷取常用的方式如下:

5.2 需求分析

利用各種需求擷取的方式,你獲得了許多跟即將開發的系統相關的資料。這些資料可能很凌亂,雜亂無章,因此你必須將這些資料做整理與分析。

5.2.1 需求的種類

5.2.2 需求分析描述

5.2.3 Event Diagram

我們可以利用事件圖(Event Diagram)來思考辨識事件,如figure 1

Fig. 1: 事件圖思考方式

除了一般的事件圖外,亦可使用CRUD圖。CRUD是由create、retrieve、update與delete的第一個字母所組成的縮寫,利用我們對資料的動作來捕捉事件,對於發覺隱性的功能或是使用者相當有用。

Fig. 2: CRUD使用範例之1

Fig. 3: CRUD使用範例之2

5.2.4 Event Table

當你歸納出事件之後,可以將之紀錄於表格中,成為事件表。 事件表是用來記錄系統功能很有用的工具。不要擔心功能到底需要怎麼被實現出來,先把系統當成一個黑盒子。這樣做的好處是讓參與計畫的人員能將焦點放在系統高層次的觀點,從外部來看系統,而不是系統內部的運作情況。在很多的經驗中我們發現人們一般都把焦點放在系統的How, 而不是系統的What。這一點要值得注意。

Event Trigger Source Activity Response Destination Priority Due Date
顧客下訂單 資料(訂單資料輸入) 顧客 在資料庫中產生一筆新訂單 1. 訂單編號 2. 訂單 出貨部門 M 2014/10/1
產生月報表 時間(每月5號) 系統 依據資料庫內的資料產生前一個月份的報表 月報表 經理 S 每月5號
Tab. 1: Event Tabale範例

5.2.5 Glossary(詞彙表)

事件表固然記錄了系統所應提供的功能,可是,在任何事件的過程中都會牽涉到許多領域中的資料,概念。你要利用詞彙表將它紀錄、整理下來。詞彙表將在後面有很大的作用。對於不清楚的詞彙也要一併記錄下來。然後在與相關客戶人員討論以求得更進一步的了解

詞彙 解釋
登入資料 帳號、密碼
訂單 訂單包含有客戶資料、訂購項目
客戶資料 客戶編號、姓名、住址、電話、email
訂購項目 編號、音樂CD摘要
音樂CD 音樂CD摘要、曲目
音樂CD摘要 專輯名稱、演唱者、類型、單價、出版商
曲目 歌曲名稱、時間長度、作詞者、作曲者、歌詞
月報表 (格式待查)
客服建言 發言者、主題、內容、日期
Tab. 2: 詞彙表範例

5.3 軟體需求規格

建議至少應包含整體系統的描述與到功能性需求與非功能性需求,可使用下列項目表達:

* Context Diagram
* 功能性需求
* Event Table
* UML - Use Case Diagram/Form
* SysML Requirement Diagram
* 非功能性需求
* SysML Requirement Diagram

5.4 Context Diagrams

Fig. 4: 一個Context Diagrams範例

figure 4為一個簡單的示範,但在圖示方面可以參考以下的建議:

Fig. 5: 採用標準圖示的Context Diagram範例

以我們欲開發的ezERD為例,其Context Diagram可以表達如figure 6

Fig. 6: ezERD的Context Diagram

figure 6顯示了使用者可以透過ezERD完成ERD的設計,並可輸出對應的資料庫綱要給MySQL資料庫。

5.5 Use Case Diagrams

Fig. 7: Use Case Diagram範例

5.5.1 Actors

Actor Specification
Actor Name:
Type: (Primary/Secondary) Personality: (initiator, external, receiver or facilitator) Abstract: (Yes/No)
Role Description:
Actor Goals: (no need to fill this box for secondary actors)
Use Case Involved with: (events that fulfill goals above; a goal will map to one or more use cases; a use case will map to one or more primary actor goals; no need to fill this box initially, only after use cases have been identified.
Actor Specification
Actor Name: Customer
Type: Primary Personality: initiator Abstract: No
Role Description: A customer is a person who has opened an account with the bank. The customer is the main reason for the existence of ATM machines. The customer interacts with the ATM to obtain convenient banking services at times when he/she cannot or is not convenient to obtain such services at the bank's premises.
Actor Goals: * Withdraw cash
* Deposit funds
* Make transfers
* Inquire balances
Use Case Involved with: * Withdraw funds
* deposit funds
* manage account (make transfers, inquire balances)

以ezERD為例,其使用者的Actor Specification可以寫做如下:

Actor Specification
Actor Name: 使用者
Type: Primary Personality: initiator Abstract: No
Role Description: 使用者為ezERD軟體的主要操作者,透過使用ezERD軟體,使用者可以繪製新的ERD、並與MySQL資料庫連結建立對應的資料庫綱要
Actor Goals: * 繪製ERD
* 連結MySQL伺服器
* 產生關聯式資料庫綱要
Use Case Involved with: * ERD編輯
* MySQL資料庫連結
* 產生資料庫綱要 (含database選擇或建立)

5.5.2 Use Cases

5.5.3 Use Case Diagram Symbols

Fig. 8: 使用Use Case的範例1 Fig. 9: 使用Use Case的範例2

Fig. 10: ezERD的Use Case圖

5.5.4 Use case modeling process

Fig. 11: Use case modeling process

5.5.4.1 Initial Use Cases

Use Case ID
Use Case
Actors
Description
Priority (only if you have this information at this point)
Non-Functional Requirements (only if noteworthy at this point)
Assumptions (only if noteworthy at this point)
Source

Example:

Use Case ID UC-100
Use Case Withdraw Funds
Actors (P) Customer
Description The customer inserts card in the ATM, logs in with a pass code, and makes a selection from the available choices to withdraw funds. Once in the funds withdrawal screen, the customer is prompted to enter the amount to withdraw. After the amount is entered, the system will check for availability of funds for that customer. Provided that funds are available, the system will dispense the amount requested in cash and then debit that amount in the customer’s bank account records.
Priority High
Non-Functional Requirements Cash dispensed within 10 seconds after amount is entered
Assumptions Customer speaks English
Source Bank’s Operational Procedures Manual

Example for the ezERD:

Use Case ID ezUC-001
Use Case ERD繪製
Actors (P) 使用者
Description 使用者可以透過ezERD軟體進行ERD的繪製。
Priority Medium
Non-Functional Requirements 必須採用WYSIWYG的方式繪製的向量的ERD,且必須符合ERD的規則。
Assumptions 假設使用者不需要存檔的功能
Source 使用者訪談(附訪談記錄)

5.5.4.2 Base Use Cases

Fig. 12: Base use cases與 initial use case

Use Case ID
Use Case
Actors
Description (brief)
Pre-conditions
Flow of Events 1.
1.1
1.2
2.
Post-conditions
Alternative Flows (briefly described)
Priority (High, Medium or Low)
Non-Functional Requirements (only those associated with this use case, if any)
Assumptions
Outstanding Issues
Source
Use Case ID UC-100
Use Case Withdraw Funds
Actors (P) Customer
Description Customer logs in, selects withdraw funds, enters an amount and receives cash and receipt
Pre-conditions Welcome screen is on
Flow of Events 1. Customer slides card in and out
2. Machine prompts customer for password
3. Customer enters password
4. System authenticates customer
5. System presents user with a choice menu
6. Customer selects Withdraw Funds option
7. System asks customer to select account
8. Customer selects account
9. System asks customer for amount to withdraw
10. Customer enters amount
11. System dispenses cash and prints receipt
12. System logs customer out
Post-conditions Welcome screen is back on
Alternative Flows Customer may not be authenticated; customer may not have sufficient funds; machine may not have enough cash
Priority High
Non-Functional Requirements Cash dispensed within 10 seconds after amount is entered
Assumptions Customer speaks English
Source Bank’s Operational Procedures Manual

以我們的ezERD為例,其base use case如下:

Use Case ID ezUC-001
Use Case ERD繪製
Actors (P) Customer
Description Customer logs in, selects withdraw funds, enters an amount and receives cash and receipt
Pre-conditions Welcome screen is on
Flow of Events 1. Customer slides card in and out
2. Machine prompts customer for password
3. Customer enters password
4. System authenticates customer
5. System presents user with a choice menu
6. Customer selects Withdraw Funds option
7. System asks customer to select account
8. Customer selects account
9. System asks customer for amount to withdraw
10. Customer enters amount
11. System dispenses cash and prints receipt
12. System logs customer out
Post-conditions Welcome screen is back on
Alternative Flows Customer may not be authenticated; customer may not have sufficient funds; machine may not have enough cash
Priority High
Non-Functional Requirements Cash dispensed within 10 seconds after amount is entered
Assumptions Customer speaks English
Source Bank’s Operational Procedures Manual

5.5.4.3 Fully Elaborated Use Cases

7. If ATM machine is out of cash
	7.1 Notify customer of no cash availability
	7.2 Log customer out
	7.3 Notify ATM service group

Fig. 13: 從base use case延展至elaborated use case (with conditional flow of events)

Use Case ID
Use Case
Actors
Description
Pre-conditions
Flow of Events 1.
2. If xx go to 8 (conditional flow)
3.
4. If yy go to Use Case UC 101-A1 (alternative flow)
5. Etc
Conditional Flows 8. (list/describe relevant events and return to 3)
9. Etc.
Post-conditions
Alternative Flows (if simple, briefly describe it; if long or complex, move to a separate Use Case)
Priority (High, Medium or Low)
Non-Functional Requirements (only those associated with this use case, if any)
Assumptions
Outstanding Issues
Source
Use Case ID
Use Case
Actors
Description
Pre-conditions
Flow of Events 1.
2. If xx (conditional flow listed when it occurs)
2.1
2.2
3.
4. if yy go to Use Case UC 101-A1
5. etc
Post-conditions
Alternative Flows (if simple, briefly describe it; if long or complex, move to a separate Use Case)
Priority (High, Medium or Low)
Non-Functional Requirements (only those associated with this use case, if any)
Assumptions
Outstanding Issues
Source
Use Case ID UC-100
Use Case Withdraw Funds
Actors (P) Customer
Description Customer logs in, selects withdraw funds, enters amount, gets cash
Pre-conditions Welcome screen is on
Flow of Events 1. Customer slides card in and out
2. Machine prompts customer for password
3. Customer enters password
4. If password is incorrect
4.1 go back to step 2
4.2 if password is incorrect 3 times
4.2.1 Retain card and notify user
4.2.2 go to step 13
5. System authenticates customer
6. System presents user with a choice menu
7. Customer selects Withdraw Funds option
8. System asks customer to select account
9. Customer selects account
10. System asks customer for amount to withdraw
11. Customer enters amount
12. System dispenses cash and prints receipt
13. System logs customer out
Post-conditions Customer is logged out an welcome screen is back on
Alternative Flows Customer may not have sufficient funds; machine may not have enough cash
Priority High
Non-Functional Requirements Cash dispensed within 10 seconds after amount is entered
Assumptions Customer speaks English
Source Bank's Operational Procedures Manual

Fig. 14: alternative use cases

Use Case ID (same ID as the base Use Case ID, but with suffix A1, A2, etc.; e.g., UC 101-A1)
Use Case
Actors (same as Base Use Case’s Actors)
Description
Insertion Point (step in Base Use Case where this alternative flow should be inserted)
Pre-conditions (clearly indicate under which conditions trigger the alternative flow)
Alternative Flow of Events 1.
2.
3.
Conditional Flows (within the Alternative flow)
Post-conditions
Priority
Non-Functional Requirements
Assumptions
Outstanding Issues
Source

Example:

Use Case ID UC-100
Use Case Withdraw Funds
Actors (P) Customer
Description Customer logs in, selects withdraw funds, enters amount, gets cash
Pre-conditions Welcome screen is on
Flow of Events 1. Customer slides card in and out
2. Machine prompts customer for password
3. Customer enters password
4. If password is incorrect
<html>&nbsp;&nbsp;&nbsp;&nbsp;</html> 4.1 If card used was reported stolen execute UC-100-A1
<html>&nbsp;&nbsp;&nbsp;&nbsp;</html> 4.2 go back to step 2
<html>&nbsp;&nbsp;&nbsp;&nbsp;</html> 4.3 If password is incorrect 3 times
<html>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</html> 4.3.1 Retain card and notify user
<html>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</html> 4.3.2 go to step 13
5. System authenticates customer
6. System presents user with a choice menu
7. Customer selects Withdraw Funds option
8. System asks customer to select account
9. Customer selects account
10. System asks customer for amount to withdraw
11. Customer enters amount
12. System dispenses cash and prints receipt
13. System logs customer out
Post-conditions Welcome screen is back on
Alternative Flows Customer may not have sufficient funds; machine may not have enough cash.
Priority High
Non-Functional Requirements Cash dispensed within 10 seconds after amount is entered
Assumptions Customer speaks English
Source Bank's Operational Procedures Manual
Use Case ID UC-100-A1
Use Case Withdraw Funds Alternative for Stolen Card Use
Actors (P) Customer
Description Notify security when use of a stolen card is detected
Insertion Point UC-100, flow 4.1
Pre-conditions User entered incorrect password and card had been reported stolen
Flow of Events 1.Immediately notify bank security
2.Place a call to local authorities
3.Take multiple pictures with ATM camera
4.Interact with user as if it were a normal transaction
5.Disable cash dispensing functions temporarily
6.Introduce processing delays to keep customer distracted
7.Retain card
8.Timeout if user stops interacting with ATM 30 seconds or more
9.Timeout if new user inserts a legitimate card
10.System logs customer out
Post-conditions Welcome screen is back on
Alternative Flows
Priority High
Non-Functional Requirements
Assumptions System has local authority notification feature
Source Bank’s Operational Procedures Manual
5.5.4.3.1 Extended Use Cases

Fig. 15: Extended Flows

Fig. 16: Extended Use Case 1 Fig. 17: Extended Use Case 2

Use Case ID (same as the base Use Case ID, but with suffix E1, E2, etc.; e.g., UC 101-E1)
Use Case
Actors (same as Base Use Case’s Actors)
Description
Extended Use Case
Extension Point (step in Base Use Case where this extension occurs)
Guard Conditions (precondition in the Extended Use Case that triggers the extension)
Alternative Flow of Events 1.
2.
3.
Conditional Flows (within the Extended flows)
Post-conditions
Priority
Non-Functional Requirements
Assumptions
Outstanding Issues
Source
Use Case ID UC-100-E1
Use Case Print bank statement for a fee
Actors (P) Customer
Description Allows customer to print a bank statement with balances and transactions in the last 30 days for a $1 fee
Extended Use Case UC-100 Withdraw Funds
Extension Point UC-100; after flow step 12
Guard Conditions Statement printing option is implemented and enabled
Flow of Events 1. Ask customer if he/she would like a printed bank statement
2.If customer says yes
2.1 Notify customer of a $1 charge for this service
2.2 Prompt customer to continue or cancel
2.3 If customer selects continue
2.3.1 Print statement
2.3.2 Debit $1 from customer’s account
2.3.3 Display thank you note
Post-conditions Return to UC-100 and continue on flow step 13
Alternative Flows
Priority Low
Non-Functional Requirements Statement must print within 20 seconds
Assumptions
Source Bank’s Operational Procedures Manual

5.5.4.4 Refactoring and Included Use Cases

Fig. 18: Included Use Case

* Notation for the Included Relationship

Fig. 19: Included Relationship 1 Fig. 20: Included Relationship 2

Use Case ID (use IUC suffix instead of UC; e.g., IUC 001)
Use Case
Description
Including Use Cases (list Use Cases that use in this included Use Case)
Pre-conditions
Alternative Flow of Events 1.
2.
3.
Conditional Flows (within the included flows)
Post-conditions
Priority
Non-Functional Requirements
Assumptions
Outstanding Issues
Source
Use Case ID UC-100
Use Case Withdraw Funds
Actors (P) Customer
Description Customer logs in, selects withdraw funds, enters amount, gets cash
Pre-conditions Welcome screen is on
Flow of Events 1. Include IUC-001 Log in and Authenticate Customer
2. If not successful, go to step 10
3. System presents user with a choice menu
4. Customer selects Withdraw Funds option
5. System asks customer to select account
6. Customer selects account
7. System asks customer for amount to withdraw
8. Customer enters amount
9. System dispenses cash and prints receipt
10. System logs customer out
Post-conditions Welcome screen is back on
Alternative Flows Customer may not have sufficient funds; machine may not have enough cash.
Priority High
Non-Functional Requirements Cash dispensed within 10 seconds after amount is entered
Assumptions Customer speaks English
Source Bank's Operational Procedures Manual
Use Case ID IUC-001
Use Case Login and Authenticate Customer
Description Customer logs, gets authenticated, card is checked against stolen reports
Including Use Cases UC-101 Withdraw Funds; UC-102 Deposit Funds; UC-103 Other transactions
Pre-conditions ATM has detected a card in the slot
Flow of Events 1. Customer slides card in and out
2. Machine prompts customer for password
3. Customer enters password
4. If password is incorrect
<html>&nbsp;&nbsp;&nbsp;&nbsp;</html> 4.1 If card used was reported stolen execute IUC-001-A1
<html>&nbsp;&nbsp;&nbsp;&nbsp;</html> 4.2 go back to step 2
<html>&nbsp;&nbsp;&nbsp;&nbsp;</html> 4.3 If password is incorrect 3 times
<html>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</html> 4.3.1 Retain card and notify user
<html>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</html> 4.3.2 System logs customer out and ends this transaction
5. System authenticates customer
Post-conditions System is back on the next flow step right after this included case was invoked
Alternative Flows
Priority High
Non-Functional Requirements Authentication should take place within 20 seconds after password entered
Assumptions Customer speaks English
Source Bank's Operational Procedure Manual

5.5.4.5 Generalization Relationships

Fig. 21: Generalized Use Case 1 Fig. 22: Generalized Use Case 2

5.5.5 Important Rules about Use Case Models