Transcript 投影片 1

Software Engineering for Digital Home
單元3:軟體設計
Chapter 3-6 – Specifying Interfaces
Software Engineering for Digital Home
Outline
• Introduction
• Interface specification
– Identifying missing attributes and operations
– Specifying type, visibility and signature
– Specifying contracts
• Discussions and Exercises
2
Software Engineering for Digital Home
Software lift cycle
Requirements
Engineering
Requirements
Elicitation
Design
Implementation
Testing
System design
Analysis
Object design
Development cycle
SRS
Analysis Model
(Class diagrams)
Subsystem
(Class diagram)
Maintenance
Software life cycle
3
Software Engineering for Digital Home
Use case
Use case name
建立作業
Participating actors Initiated by 老師
Flow of events
1.
2.
3.
4.
老師要建立作業.
老師輸入作業的名稱(50字元), 作業的要求(2000字元), 截止日期(日
期格式).
系統檢查輸入的作業名稱,作業的要求, 截止日期是否正確.
如果正確, 系統就建立作業.
Exceptions
3.1 如果所輸入的資料不正確, 系統要求使用者重新輸入.
Entry condition
老師己登入教學網站.
Exit conditions
老師在教學網站上建立了一個新的作業.
4
Software Engineering for Digital Home
Class diagram
AssignmentControl
AssignmentForm
checkdata()
createAssignment()
set( name, context, due )
Assignment
name
context
duedate
5
Software Engineering for Digital Home
Interface specification
Subsystem decomposition
Interface specification
Analysis
Refine class
using design pattern
Identifying missing
attributes and operations
Class diagrams
Specifying type,
Visibility and signature
Object Design Document
Specifying Contracts
Class interfaces
6
Software Engineering for Digital Home
Identifying missing attributes and
operations
• 分析後得到的class diagrams常常會漏掉很多attribute與
operation,因為我們只把use cases轉成class diagram僅描述
系統功能
AssignmentControl
AssignmentForm
checkdata()
createAssignment()
setData( name, context, due )
Assignment
name
context
duedate
7
Software Engineering for Digital Home
Identifying missing attributes and
operations
• 使用文字來說明作業內容學生不易於了解作業需
求
• 一般人對於圖片和範例等表現方式比較容易了其
意義
• 提供作業附件功能方便學生能夠藉由附件更了解
作業內容
8
Software Engineering for Digital Home
Identifying missing attributes and
operations
AssignmentControl
AssignmentForm
AssignmentForm
createAssignment()
createAssignment()
setData(
setData(
name,
name,
context,
context,
due,
duefile
) )
checkdata()
checkdata()
uploadAttachment(file)
Assignment
name
name
context
context
duedate
duedate
attachment
9
Software Engineering for Digital Home
Type, Visibility and Signature
• Type (Attributes)
– Name: string
– maxNumPlayers: int
– Start: date
• Visibility (Attributes and Operations)
– Private: – protected: #
– public: +
• Signature (Operations)
– acceptPlayer(Player): void
– getMaxNumPlayers(void): int
10
Software Engineering for Digital Home
Specifying type, visibility and
signature
• Specifying the range of each attribute.
(首先確定我們需要什麼類型及範圍的型態)
• We determine which types provided by the development environment.
(接著看開發環境上有什麼型態符合我們第一步找出的需求類型及範圍)
AssignmentForm
+createAssignment()
+set( name, context, due, file )
AssignmentControl
+checkdata():bool
+uploadAttachment(file)
Assignment
+name:String
+context:String
+duedate:Date
+attachment:File
11
Software Engineering for Digital Home
Contracts
• Invariant
– Specifying consistency constraints among class attributes.
(凡屬於class的所有instances都要符合的限制)
• Precondition
– Specifying constrains that a class user meet before calling
the operation.
(new了一個class後,要使用它的operation前必須符合的限制)
• Postcondition
– It’s a predicate that must be true after an operation is
invoked.
(執行了operation後必定會成立的條件)
12
Software Engineering for Digital Home
Contract Notation
• OCL, Object Constraint Language [OMG, 1998].
• A constraint is expressed as a boolean expression returning the
value True or False.
(描述限制的式子回傳值皆為boolean型態)
context AssignmentControl inv:
//Condition (s)
Keyword: context
Class or Operation
Constraint type
AssignmentControl
AssignmentControl ::checkdata()
inv <<invariant>>
pre <<precondition>>
post <<postcondition>>
Expression
self.getSize(f) < 3145728
13
Software Engineering for Digital Home
Specifying contracts
Public class AssignmentControl{
AssignmentControl
/* The Course exist at all times.*/
context AssignmentControl inv:
isCourseExist(id)
+checkdata():bool
+uploadAttachment( file: File):boolean
-getLength(data:String): int
-getSize(f:File): int
-checkType(f:File): boolean
-isCourseExist(id:int):boolean
-isAttachmentUpload(f:File):boolean
context AssignmentControl::uploadAttachment(file) pre:
checkType(f) and
getSize(f) < 3145728
context AssignmentControl::uploadAttachment(file) post:
isAttachmentUpload(f)
…
}
14
Software Engineering for Digital Home
Exercises
• Exercises
– 每一個operation都有precondition以及
postcondition嗎?
– 試以教學網站的analysis model設計class
interface.
15