Object Oriented Analysis and Design Using the UML

Download Report

Transcript Object Oriented Analysis and Design Using the UML

Giáo trình Phân tích và thiết kế hướng đối tượng bằng UML
Phân tích Use-Case
Phân tích Use-Case
Dương Anh Đức
1
Mục tiêu
 Tìm hiểu mục đích của công đoạn Use-Case Analysis vị trí của
nó trong chu kỳ sống của qui trình phát triển phần mềm
 Xác định các class thực hiện một use- case flow of events
 Phân phối các hành vi (behaviour) của use-case về các class
của nó, thông qua việc xác định nhiệm vụ của các class
 Phát triển các use-case realization mô hình hóa collaboration
giữa các thể hiện của các class đã xác định
Phân tích Use-Case
Dương Anh Đức
2
Use-Case Analysis trong ngữ cảnh
Architectural
Analysis
Architectural
Design
Architect
Describe
Concurrency
Review the
Design
Use-Case
Design
Class
Design
Phân tích Use-Case
Dương Anh Đức
Review the Architecture
Architecture Reviewer
Subsystem Design
Use-Case
Analysis
Designer
Describe
Distribution
3
Design
Reviewer
Tổng quan Use-Case Analysis
Software Architecture
Glossary Use-Case
Document
Modeling Guidelines
Supplementary
Specifications
Use-Case Realization
(identified)
Use-Case Model
Phân tích Use-Case
Dương Anh Đức
Use-Case
Analysis
Analysis Model (optional)
4
Analysis Classes
Use-Case Realization
(developed)
Design Model
Các bước trong Use-Case Analysis
 Bổ sung mô tả Use-Case
 Với mỗi use-case realization
 Tìm các Class từ Use-Case Behavior
 Phân bổ Use-Case Behavior về các Class
 Với mỗi analysis class đã tìm thấy
 Mô tả nhiệm vụ của chúng
 Mô tả các Attribute và các Association
 Lượng giá (qualify) các Analysis Mechanism
 Hợp nhất các Analysis Class
 Checkpoints
Phân tích Use-Case
Dương Anh Đức
5
Các bước trong Use-Case Analysis
 Bổ sung mô tả Use-Case
 Với mỗi use-case realization
 Tìm các Class từ Use-Case Behavior
 Phân bổ Use-Case Behavior về các Class
 Với mỗi analysis class đã tìm thấy
 Mô tả nhiệm vụ của chúng
 Mô tả các Attribute và các Association
 Lượng giá (qualify) các Analysis Mechanism
 Hợp nhất các Analysis Class
 Checkpoints
Phân tích Use-Case
Dương Anh Đức
6
Supplement the Use-Case Description
• Hệ thống truy vấn và
hiển thị một danh sách
các lớp học đang mở
từ CSDL course
catalog kế thừa từ hệ
thống cũ.
• Hệ thống
hiển thị một
danh sách
các lớp học
(course
offerings).
Phân tích Use-Case
Dương Anh Đức
7
Các bước trong Use-Case Analysis
 Bổ sung mô tả Use-Case
 Với mỗi use-case realization
 Tìm các Class từ Use-Case Behavior
 Phân bổ Use-Case Behavior về các Class
 Với mỗi analysis class đã tìm thấy
 Mô tả nhiệm vụ của chúng
 Mô tả các Attribute và các Association
 Lượng giá (qualify) các Analysis Mechanism
 Hợp nhất các Analysis Class
 Checkpoints
Phân tích Use-Case
Dương Anh Đức
8
Review: Class
 Là một sự trừu tượng hóa
 Mô tả một nhóm các đối tượng có chung:
 Properties (attributes)
 Behavior (operations)
 Relationships
 Ngữ nghĩa (Semantics)
Class Name
Professor
name
empID
create( )
save( )
delete( )
change( )
Attributes
Operations
Phân tích Use-Case
Dương Anh Đức
9
Review: Use-Case Realization
Use-Case Model
Design Model
Use Case
Use-Case Realization
Sequence Diagrams
Collaboration Diagrams
Use Case
Phân tích Use-Case
Dương Anh Đức
Class Diagrams
10
Tìm các Class từ Use-Case Behavior
 Toàn bộ hành vi của một use case phải được phân bổ về cho
các analysis class
<<boundary>>
<<control>>
<<boundary>>
<<entity>>
<<entity>>
Phân tích Use-Case
Dương Anh Đức
11
Thế nào là một Analysis Class?
<<boundary>>
<<control>>
System
boundary
Use-case
behavior
coordination
System
information
Phân tích Use-Case
Dương Anh Đức
12
<<entity>>
Analysis Classes: A First Step Towards Executables
Use Cases
Analysis Design
Classes Elements
Use-Case Analysis
Phân tích Use-Case
Dương Anh Đức
13
Source
Code
Exec
Thế nào là một Boundary Class?
 Làm trung gian giao tiếp với những gì nằm ngoài hệ thống
 Một số kiểu
 Các User interface class
 Các System interface class
 Các Device interface class
 Một boundary class cho 1 cặp actor/use case
Analysis class
stereotype
<<boundary>>
Phụ thuộc môi trường
Phân tích Use-Case
Dương Anh Đức
14
Vai trò của Boundary Class
<<boundary>>
<<control>>
<<boundary>>
Customer
<<boundary>>
<<entity>>
<<entity>>
Mô hình hóa sự tương tác giữa system và môi trường của nó
Phân tích Use-Case
Dương Anh Đức
15
Ví dụ: Tìm các Boundary Class
 Một boundary class cho 1 cặp actor/use case
Student
Register for Courses
<<boundary>>
RegisterForCoursesForm
Phân tích Use-Case
Dương Anh Đức
Course Catalog System
<<boundary>>
CourseCatalogSystem
16
Guidelines: Boundary Class
 Các User Interface Class
 Tập trung vào những thông tin gì được thể hiện cho người
dùng
 KHÔNG tập trung vào các chi tiết UI
 Các System và Device Interface Class
 Tập trung vào những protocols nào phải định nghĩa
 KHÔNG tập trung vào cách mà các protocol sẽ được cài đặt
Tập trung vào các nhiệm vụ, chứ không phải chi tiết!
Phân tích Use-Case
Dương Anh Đức
17
Thế nào là một Entity Class?
 Các trừu tượng hóa then chốt của system
Analysis class
stereotype
<<entity>>
Glossary
Use Case
Business-Domain Model
Architectural Analysis
Abstractions
Phân tích Use-Case
Dương Anh Đức
Độc lập môi trường
18
Vai trò của Entity Class
<<boundary>>
<<control>>
<<boundary>>
Customer
<<boundary>>
<<entity>>
<<entity>>
Lưu trữ và quản trị các thông tin trong system
Phân tích Use-Case
Dương Anh Đức
19
Ví dụ: Tìm các Entity Class
 Dùng use-case flow of events như input
 Các trừu tượng hóa then chốt của use case
 Hướng tiếp cận truyền thống (nouns filtering)
 Gạch dưới các cụm danh từ trong flow of events
 Loại bỏ các ứng viên dư thừa
 Loại bỏ các ứng viên mơ hồ, không rõ ràng
 Loại bỏ các actor (ngoài phạm vi)
 Loại bỏ các kiến trúc cài đặt
 Loại bỏ các attribute (để lại dùng sau)
 Loại bỏ các operation
Phân tích Use-Case
Dương Anh Đức
20
Ví dụ: Candidate Entity Class
 Register for Courses (Create Schedule)
Student
CourseOffering
Schedule
Phân tích Use-Case
Dương Anh Đức
21
Review: Generalization
 Một class chia sẻ cấu trúc
và/hoặc hành vi của một hay
nhiều class
Superclass
 Mối quan hệ “Là một dạng
(parent)
của”
 Trong phân tích, sử dụng ở
mức độ đơn giản, sơ sài
Account
balance
name
number
Withdraw()
CreateStatement()
Generalization
Relationship
Checking
Savings
Withdraw()
GetInterest()
Withdraw()
Subclasses
Phân tích Use-Case
Dương Anh Đức
22
Finding Generalization: Generalization of Classes
Stock
Savings
RealEstate
Bond
Asset
BankAccount
Savings
Phân tích Use-Case
Dương Anh Đức
Tổng quát hơn
Checking
Security
Checking
Stock
23
RealEstate
Bond
Finding Generalization: Specialization of Classes
Asset
Asset
BankAccount
Savings
Phân tích Use-Case
Dương Anh Đức
Checking
Security
Stock
24
RealEstate
Bond
Chuyên biệt hơn
Example: Generalization (Chia sẻ ngữ nghĩa)
Không có sự
tổng quát hóa
Part-timeStudent
Full-timeStudent
name
address
studentID
numberCourses
name
address
studentID
gradDate
Student
Có sự tổng quát
hóa
name
address
studentID
ParttimeStudent
FulltimeStudent
gradDate
Phân tích Use-Case
Dương Anh Đức
maxNumCourses
25
Thế nào là một Control Class?
 Nhà điều phối các hành vi của Use-case
 Chỉ một control class cho một use case
<<control>>
Use Case
Analysis class
stereotype
Phụ thuộc use-case, độc lập môi trường
Phân tích Use-Case
Dương Anh Đức
26
Vai trò của Control Class
<<boundary>>
<<control>>
<<boundary>>
Customer
<<boundary>>
<<entity>>
<<entity>>
Điều phối các hành vi của use-case
Phân tích Use-Case
Dương Anh Đức
27
Ví dụ: Tìm các Control Class
 Một control class cho một use case
Student
Register for Courses
Course Catalog System
<<control>>
RegistrationController
Phân tích Use-Case
Dương Anh Đức
28
Example: Summary: Analysis Classes
Student
Register for Courses
Course Catalog System
Use-Case Model
Design Model
<<boundary>>
RegisterForCoursesForm
<<entity>>
Student
Phân tích Use-Case
Dương Anh Đức
<<control>>
RegistrationController
<<entity>>
Schedule
29
<<boundary>>
CourseCatalogSystem
<<entity>>
CourseOffering
Các bước trong Use-Case Analysis
 Bổ sung mô tả Use-case
 Với mỗI use-case realization
 Tìm các Class từ Use-Case Behavior
 Phân bổ Use-Case Behavior về các Class
 Với mỗi analysis class đã tìm thấy
 Mô tả nhiệm vụ của chúng
 Mô tả các Attribute và các Association
 Lượng giá (qualify) các Analysis Mechanism
 Hợp nhất các Analysis Class
 Checkpoints
Phân tích Use-Case
Dương Anh Đức
30
Phân bổ Use-case về các Class
 Đối với mỗi use-case flow of events:
 Xác định các analysis class
 Gắn kết các trách nhiệm của use-case cho các analysis
class
 Mô hình hóa tương tác của các analysis class trong
interaction diagram
Sequence Diagrams
Use Case
Phân tích Use-Case
Dương Anh Đức
Collaboration Diagrams
Use-Case Realization
31
Interaction Diagrams
 Generic term that applies to several diagrams
that emphasize object interactions
 Sequence Diagram
 Time oriented view of object interaction
Sequence Diagrams
 Communication Diagram
(or Collaboration Diagram)
 Structural view of messaging objects
Communication
Diagrams
Phân tích Use-Case
Dương Anh Đức
32
Guidelines: Allocating Responsibilities to Classes
 Dùng các A.Class stereotype làm guide:
 Các Boundary Class
• Các hành vi liên quan đến sự giao tiếp với actor
 Các Entity Class
• Các hành vi liên quan đến dữ liệu được gói trong một
abstraction
 Các Control Class
• Các hành vi đặc thù cho một use case hoặc một phần rất
quan trọng của flow of events
(còn tiếp)
Phân tích Use-Case
Dương Anh Đức
33
Guidelines: Allocating Responsibilities to Classes (tt)
 Ai có dữ liệu cần cho việc thực hiện nhiệm vụ?
 Một class có dữ liệu, hãy để nhiệm vụ cùng với dữ liệu
 Nhiều class có dữ liệu :
• Hãy để nhiệm vụ trong 1 class và thêm quan hệ với các
class khác.
• Tạo một class mới, để nhiệm vụ trong class mới này, và
thêm quan hệ với các class cũ
• Hãy để nhiệm vụ trong control class, và thêm quan hệ
với các class cần để thực hiện nhiệm vụ
Phân tích Use-Case
Dương Anh Đức
34
The Anatomy of Sequence Diagrams
Supplier Object
Client Object
:Supplier
:Client
Object Lifeline
Reflexive Message
1: PerformResponsibility
Đây là một script
mẫu
1.1: PerformAnother
Responsibility
Message
Hierarchical Message
Numbering
Focus of Control
Phân tích Use-Case
Dương Anh Đức
35
Register for Courses Use Case –
Basic flow: Create a Schedule
1. The Student selects "create schedule."
2. The system retrieves a list of available course
3.
4.
5.
6.
offerings from the Course Catalog System.
The system displays a blank schedule form.
The Student selects 4 primary course offerings and 2
alternate course offerings from the list of available
offerings. Once the selections are complete the
Student selects "submit."
Hệ thống tạo một lịch học chứa những học phần sinh
viên đã đăng ký.
Sinh viên kiểm tra và xác nhận lịch học, Submit
Schedule được thực thi.
Phân tích Use-Case
Dương Anh Đức
36
Analysis Classes
Phân tích Use-Case
Dương Anh Đức
37
Example: Sequence Diagram
: Student
:
RegisterForCoursesForm
:
RegistrationController
:
CourseCatalogSystem
: Course Catalog
1. // create schedule( )
1.1. // get course offerings( )
Student wishes to
create a new
schedule
1.1.1. // get course offerings(forSemester)
1.1.1.1. // get course offerings( )
A list of the available
course offerings for this
semester are displayed
A blank schedule
is displayed for the
students to select
offerings
1.2. // display course offerings( )
1.3. // display blank schedule( )
2. // select 4 primary and 2 alternate offerings( )
2.1. // create schedule with offerings( )
2.1.1. // create with offerings( )
2.1.2. // add schedule(Schedule)
At this, point the Submit Schedule subflow is executed.
Phân tích Use-Case
Dương Anh Đức
38
: Schedule
: Student
Example: Sequence Diagram (cont.)
: RegisterForCoursesForm
: RegistrationController
: Schedule
: Student
:
: CourseOffering
PrimaryScheduleOfferingInfob
1. // submit schedule( )
1.1. // submit schedule( )
1.1.1. // save( )
1.1.2. // submit( )
1.1.2.1. // is selected?( )
[ is selected ]
1.1.2.2. // has pre-requisites(CourseOffering)
Repeat for all primary
course offerings.
An attempt is made
to register the
student for all
selected course
offerings
1.1.2.3. // still open?( )
1.1.2.4. // any conflicts?( )
[ has pre-requisites, course offering open,
and no schedule conflicts ]
1.1.2.5. // add student(Schedule)
1.1.2.6. // mark as enrolled in( )
Phân tích Use-Case
Dương Anh Đức
39
: Student
Example: Use case Withdraw of ATM
Identify Nouns
Use case: Withdraw
Actor: Client
Purpose: To allow the client to withdraw
money
Pre-conditions: User already logged-in
Post-conditions: Amount is deducted from
user’s account
Main flow:
1) Client initiates this usecase by selecting
'withdraw'
2) System displays all the accounts related to
the Card and prompts to select any one.
3) Client selects one account.
4) System prompts for the amount (fast cash or
…)
Phân tích Use-Case
Dương Anh Đức
40
Client
User
Account
Amount
Money
Card
Cash
Sequence Diagram – Use case Withdraw
: Client
: WithdrawUI
: WithdrawControl
: Card
: Account
1: // select withdraw( )
2: // get list accounts( )
3: // get accounts( )
4: // get info( )
5: // display account( )
6: // select account( )
7: // enter money( )
8: // withdraw( )
9: [enough money] // withdraw( )
Phân tích Use-Case
Dương Anh Đức
41
The Anatomy of Collaboration Diagrams
Client Object
Link
Supplier Object
:Client
:Supplier
1: PerformResponsibility
Message
Phân tích Use-Case
Dương Anh Đức
42
Example: Collaboration Diagram
1.2. // display course offerings( )
1.3. // display blank schedule( )
1. // create schedule( )
2. // select 4 primary and 2 alternate offerings( )
: RegisterForCoursesForm
: Course Catalog
: Student
1.1. // get course offerings( )
2.1. // create schedule with offerings( )
1.1.1.1. // get course offerings( )
1.1.1. // get course offerings(forSemester) : CourseCatalogSystem
: RegistrationController
2.1.1. // create with offerings( )
2.1.2. // add schedule(Schedule)
:
Schedule
: Student
Phân tích Use-Case
Dương Anh Đức
43
Example: Collaboration Diagram (cont.)
1. // submit schedule( )
: RegisterForCoursesForm
1.1.2.4. // any conflicts?( )
: Student
1.1. // submit schedule( )
1.1.1. // save( )
1.1.2. // submit( )
:
RegistrationController
1.1.2.3. // still open?( )
1.1.2.5. // add student(Schedule)
:
Schedule
1.1.2.1. // is selected?( )
1.1.2.6. // mark as enrolled in( )
:
CourseOffering
1.1.2.2. // has pre-requisites(CourseOffering)
:
PrimaryScheduleOfferingInfob
: Student
Phân tích Use-Case
Dương Anh Đức
44
One Interaction Diagram Not Good Enough
Basic Flow
Alternate Flow 1
Alternate Flow 2
Alternate Flow 3
Alternate Flow 4
Alternate Flow 5
Alternate Flow n
AF3
AF1
AF2
Phân tích Use-Case
Dương Anh Đức
45
Collaboration Diagrams Vs Sequence Diagrams
 Collaboration Diagrams
 Chỉ ra các mối quan hệ
bổ sung cho các tương
tác
 Trực quan hóa tốt hơn
các mẫu cộng tác
 Trực quan hóa tốt hơn
các hiệu ứng tác động
lên một đối tượng cụ
 Dễ sử dụng hơn trong
các vấn đề cần giải quyết
tập thể
Phân tích Use-Case
Dương Anh Đức
 Sequence Diagrams
 Chỉ ra rõ ràng chuỗi các
thông điệp
 Trực quan hóa tốt hơn
toàn bộ luồng sự kiện
 Tốt hơn cho các đặc tả
real-time và cho các
scenario phức tạp
46
Exercise: Use-Case Analysis, Part 1
 Hãy xây dựng:
 Use-Case Model, đặc biệt là các use-case flows of events
 Các trừu tượng hóa/class then chốt
 Hãy xác định các thông tin sau cho một use case cụ thể:
 Các analysis class, cùng với chúng là:
• Brief descriptions
• Stereotypes
• Responsibilities
 Các collaboration cần thiết để cài đặt use case
(còn tiếp)
Phân tích Use-Case
Dương Anh Đức
47
Exercise: Use-Case Analysis, Part 1 (tt)
 Với một use case cụ thể, hãy thiết lập:
 Use-case realization interaction diagram cho tối thiểu một
trong các use-case flows of events
Phân tích Use-Case
Dương Anh Đức
48
Các bước trong Use-Case Analysis
 Bổ sung mô tả Use-case
 Với mỗI use-case realization
 Tìm các Class từ Use-Case Behavior
 Phân bổ Use-Case Behavior về các Classs
 Với mỗI analysis class đã tìm thấy
 Mô tả nhiệm vụ của chúng
 Mô tả các Attribute và các Association
 Lượng giá (qualify) các Analysis Mechanism
 Hợp nhất các Analysis Class
 Checkpoints
Phân tích Use-Case
Dương Anh Đức
49
Describe Responsibilities
 Trách nhiệm (responsibilities) là gì?
 Làm thế nào để tìm ra chúng?
Interaction Diagram
:Client
:Supplier
// PerformResponsibility
Class Diagram
Supplier
// PerformResponsibility
Phân tích Use-Case
Dương Anh Đức
50
Example: View of Participating Classes (VOPC) Class
Diagram
<<control>>
RegistrationController
<<boundary>>
RegisterForCoursesForm
// submit schedule()
// display course offerings()
// display schedule()
// create schedule()
// select 4 primary and 2 alternate offerings()
// display blank schedule()
<<entity>>
Student
// add schedule()
// has pre-requisites()
// get course offerings()
// submit schedule()
// create schedule with offerings()
// get course offerings()
<<entity>>
Schedule
<<entity>>
ScheduleOfferingInfo
status
// create with offerings()
// submit()
// save()
// mark as selected()
// mark as cancelled()
// is selected?()
<<entity>>
CourseOffering
number : String = "100"
startTime : Time
endTime : Time
days : Enum
// add student()
// still open?()
// save()
Phân tích Use-Case
Dương Anh Đức
<<boundary>>
CourseCatalogSystem
51
<<entity>>
PrimaryScheduleOfferingInfo
grade
// is enrolled in?()
// mark as enrolled in()
Maintaining Consistency: What to Look For
 In order of criticality
 Redundant responsibilities across classes
 Disjoint responsibilities within classes
 Class with one responsibility
 Class with no responsibilities
 Better distribution of behavior
 Class that interacts with many other classes
Phân tích Use-Case
Dương Anh Đức
52
Các bước trong Use-Case Analysis
 Bổ sung mô tả Use-case
 Với mỗI use-case realization
 Tìm các Class từ Use-Case Behavior
 Phân bổ Use-Case Behavior về các Classs
 Với mỗI analysis class đã tìm thấy
 Mô tả nhiệm vụ của chúng
 Mô tả các Attribute và các Association
 Lượng giá (qualify) các Analysis Mechanism
 Hợp nhất các Analysis Class
 Checkpoints
Phân tích Use-Case
Dương Anh Đức
53
Describe Attributes and Associations
 Định nghĩa các Attribute
 Thiết lập các mối quan hệ dạng Aggregation và Association
Phân tích Use-Case
Dương Anh Đức
54
Review: What is an Attribute?
<<stereotype>>
ClassName
Attribute : Type = InitValue
Attribute : Type = InitValue
Attribute : Type = InitValue
<<entity>>
CourseOffering
attribute
Phân tích Use-Case
Dương Anh Đức
number :String=“100”
startTime : Time
endTime: Time
days: enum
55
Trong analysis, không nên
tốn nhiều thời gian cho
việc xác định các attribute
signature
Finding Attributes
 Các thuộc tính/đặc điểm của các class
 Các thông tin đc giữ lại bởi các class
 Các “danh từ” không biến thành class
 Các thông tin mà giá trị của chúng là quan trọng
 Các thông tin ddc sở hữu bởi 1 object duy nhất
 Các thông tin không có hành vi
Phân tích Use-Case
Dương Anh Đức
56
Review: What is an Association?
 Mô hình hóa một liên hệ ngữ nghĩa giữa các thể hiện
(instances) của các class
<<entity>>
Student
<<entity>>
CourseOffering
Simple
association
is a pre-requisite of
<<entity>>
Schedule
<<entity>>
Course
Reflexive
association
Association là một quan hệ cấu trúc
Phân tích Use-Case
Dương Anh Đức
57
Review: What are Roles?
 Nhân vật” mà một class “đóng vai” trong association
<<entity>>
Professor
<<entity>>
CourseOffering
Instructor
Department head
Role Name
<<entity>>
Department
Pre-requisites
<<entity>>
Course
Phân tích Use-Case
Dương Anh Đức
58
Example: Multiple Associations
primaryCourses
<<entity>>
Schedule
<<entity>>
CourseOffering
alternateCourses
<<entity>>
Schedule
add student to
remove student from
<<entity>>
CourseOffering
Các multiple association phải phản ánh các multiple role
Phân tích Use-Case
Dương Anh Đức
59
Review: Multiplicity
 Không mô tả
 Duy nhất một
 Zero hoặc nhiều (many,
unlimited)
1
0..*
*




Một hoặc nhiều
Zero hoặc 1
Một đoạn
Nhiều đoạn rời nhau
Phân tích Use-Case
Dương Anh Đức
1..*
0..1
2..4
2, 4..6
60
Example: Multiplicity
Bản số
<<entity>>
Student
1
0..*
<<entity>>
Schedule
0..4
0..*
primaryCourses
0..*
0..2
alternateCourses
Phân tích Use-Case
Dương Anh Đức
61
<<entity>>
CourseOffering
Review: Navigability
 Khả năng định hướng từ associating class đến target class
Hai chiều
Một chiều
Phân tích Use-Case
Dương Anh Đức
Class1
Class2
Class1
Class2
62
Example: Navigability
<<boundary>>
RegisterForCoursesForm
1
1
<<control>>
RegistrationController
1-way navigation
<<entity>>
Schedule
0..4
0..*
primaryCourses
0..*
0..2
<<entity>>
CourseOffering
alternateCourses
2-way navigation
Phân tích Use-Case
Dương Anh Đức
63
Review: What is Aggregation?
 Một dạng đặc biệt của association dùng để mô hình hóa một
mối quan hệ toàn thể-bộ phận giữa toàn thể và các phần của
nó
Whole/aggregate
<<entity>>
Student
1
part
0..*
<<entity>>
Schedule
0..4
0..*
primaryCourses
0..*
0..2
alternateCourses
Phân tích Use-Case
Dương Anh Đức
64
<<entity>>
CourseOffering
Association or Aggregation?
 Xem xét
 Ngữ cảnh, các đặc trưng độc lập của Class2
Class1
Class2
association
Class1
aggregation
Class2
Khi cảm thấy nghi ngờ hãy dùng association
Phân tích Use-Case
Dương Anh Đức
65
Nhận diện Aggregation
Bốn ngữ nghĩa có thể của Aggregation
 Sở hữu độc quyền (Exclusive Owns): Book has
Chapter
 Có sự phụ thuộc tồn tại (không có chapter nếu không có
book)
 Không chia sẻ
 Là thuộc tính cố định (một chapter không thể chuyển sang
book khác)
 Sở hữu (Owns): Car has Tire
 Không chia sẻ
 Không là thuộc tính cố định (có thể chuyển tire sang một car
khác)
 Có (Has): Department has Student
 Không có sự phụ thuộc tồn tại, có thể chia sẻ.
Phân tích Use-Case
Dương Anh Đức
66
Composition and Aggregation
 Aggregation cơ bản là bất kỳ quan hệ whole–
part
 Ngữ nghĩa có thể rất mơ hồ
 Tương ứng với ngữ nghĩa "Has" và "Member".
 Một đối tượng thành phần (part) có thể thuộc nhiều
hơn một đối tượng bao gồm (whole)
 Composition là Aggregation mạnh hơn
 Tại một thời điểm, mỗi đối tượng thành phần (part)
chỉ có thể thuộc chỉ một đối tượng bao gồm
(whole).
 Có sự phụ thuộc tồn tại từ "part" vào "whole"
 Khi đối tượng "whole" bị hủy thì các "part" cũng bị
hủy
Phân tích Use-Case
Dương Anh Đức
67
Aggregation and Composition
Quan hệ m*n có thể chấp nhận
CourseOffering
Student
1..*
0..*
Các Student có thể
trong nhiều
CourseOffering.
Nếu CourseOffering
bị hủy, các Student
không bị hủy!
Quan hệ m*n không được phép
Book
Chapter
1
Phân tích Use-Case
Dương Anh Đức
1..*
68
Nếu Book bị xóa, các
chương (Chapter) trong
Book cũng bị xóa!
Association Class
 Một class “được gắn” vào một association
 Chứa các thuộc tính của relationship
 Một thể hiện / 1 link
<<entity>>
ScheduleOfferingInfo
status
// mark as selected()
// mark as cancelled()
// is selected?()
0..*
alternateCourses
0..2
<<entity>>
Schedule
<<entity>>
CourseOffering
0..*
<<entity>>
PrimaryScheduleOfferingInfob
grade
Phân tích Use-Case
Dương Anh Đức
// is enrolled in?()
// mark as enrolled in()
69
// mark
as committed()
primaryCourses
0..4
Finding Relationships
1: PerformResponsibility
Collaboration
Diagram
:Client
:Supplier
Link
Client
Class
Diagram
Supplier
Client
0..*
0..*
Supplier
Prime suppliers
PerformResponsibility()
Association
Tạo Relationship cho mọi link!
Phân tích Use-Case
Dương Anh Đức
70
Example: What Associations Can You Find?
1.2. // display course offerings( )
1.3. // display blank schedule( )
1. // create schedule( )
2. // select 4 primary and 2 alternate offerings( )
: RegisterForCoursesForm
: Course Catalog
: Student
1.1. // get course offerings( )
2.1. // create schedule with offerings( )
1.1.1.1. // get course offerings( )
1.1.1. // get course offerings(forSemester) : CourseCatalogSystem
: RegistrationController
2.1.1. // create with offerings( )
2.1.2. // add schedule(Schedule)
:
Schedule
: Student
Phân tích Use-Case
Dương Anh Đức
71
Example: VOPC: Finding Relationships
<<boundary>>
RegisterForCoursesForm
1
1
<<control>>
RegistrationController
0..1
currentSchedule
0..1
<<entity>>
<<entity>>
Schedule
Student
1
Phân tích Use-Case
Dương Anh Đức
0..*
primaryCourses
0..*
72
0..4
<<entity>>
CourseOffering
Example: VOPC: Finding Relationships
<<boundary>>
RegisterForCoursesForm
// create schedule ()
// display course offerings ()
// display blank schedule
// select 4 primary and 2 alternate offerings()
1
1
<<boundary>>
CourseCatalogSystem
1
0..*
// get course offerings(forSemester)
<<control>>
RegistrationController
// get course offerings()
// create schedule with offerings
0..1
0..1
0..1
1
registrant
Phân tích Use-Case
Dương Anh Đức
currentSchedule
<<entity>>
Student
<<entity>>
Schedule
// add schedule (Schedule)
// create with offerings()
73
Example: What Associations Can You Find?
1. // submit schedule( )
: RegisterForCoursesForm
1.1.2.4. // any conflicts?( )
: Student
1.1. // submit schedule( )
1.1.1. // save( )
1.1.2. // submit( )
:
RegistrationController
1.1.2.3. // still open?( )
1.1.2.5. // add student(Schedule)
:
Schedule
1.1.2.1. // is selected?( )
1.1.2.6. // mark as enrolled in( )
:
CourseOffering
1.1.2.2. // has pre-requisites(CourseOffering)
:
PrimaryScheduleOfferingInfob
: Student
Phân tích Use-Case
Dương Anh Đức
74
Example: VOPC: Finding Relationships (tt)
<<entity>>
PrimaryScheduleOfferingInfob
grade
// is enrolled in?()
// mark as enrolled in()
<<entity>>
Schedule
primaryCourses
// cancel(theOffering : CourseOffering)
// submit()
// any conflicts?()
// create with offerings()
0..*
0..4
0..*
alternateCourses
<<entity>>
ScheduleOfferingInfo
status
// mark as selected()
// mark as cancelled()
// is selected?()
Phân tích Use-Case
Dương Anh Đức
<<entity>>
CourseOffering
number : String = "100"
startTime : Time
endTime : Time
days : Enum
75
// add student()
0..2 // cancel()
// still open?()
// save()
Use-Case Analysis Steps
 Bổ sung mô tả Use-case
 Với mỗi use-case realization
 Tìm các Class từ Use-Case Behavior
 Phân bổ Use-Case Behavior về các Classs
 Với mỗi analysis class đã tìm thấy
 Mô tả nhiệm vụ của chúng
 Mô tả các Attribute và các Association
 Lượng giá (qualify) các Analysis Mechanism
 Hợp nhất các Analysis Class
 Checkpoints
Phân tích Use-Case
Dương Anh Đức
76
Unify Analysis Classes
<<boundary>>
<<control>>
<<entity>>
Phân tích Use-Case
Dương Anh Đức
<<entity>>
77
Unify Analysis Classes
Phân tích Use-Case
Dương Anh Đức
78
Evaluate Your Results
Glossary
Design Model
Supplementary
Specification
Use-Case Model
Analysis Classes
Phân tích Use-Case
Dương Anh Đức
79
Use-Case Analysis Steps
 Bổ sung mô tả Use-case
 Với mỗi use-case realization
 Tìm các Class từ Use-Case Behavior
 Phân bổ Use-Case Behavior về các Classs
 Với mỗi analysis class đã tìm thấy
 Mô tả nhiệm vụ của chúng
 Mô tả các Attribute và các Association
 Lượng giá (qualify) các Analysis Mechanism
 Hợp nhất các Analysis Class
 Checkpoints
Phân tích Use-Case
Dương Anh Đức
80
Checkpoints: Analysis Classes
Các class có hợp lý không?
Tên của các class có phản ánh đúng vai trò của chúng?
Class có biểu diễn 1 single well-defined abstraction?
Tất cả các attribute và responsibility có gắn kết với nhau về mặt
chức năng không?
 Class có cung cấp các hành vi được y/c?
 Tất cả các yêu cầu cụ thể đã được thể hiện trên class chưa?




(còn tiếp)
Phân tích Use-Case
Dương Anh Đức
81
Checkpoints: Use-Case Realizations
 Tất cả các luồng chính và luồng con đã được điều khiển chưa,
bao gồm cả các trường hợp ngoài lệ?
 Đã tìm thấy tất cả các đối tượng cần thiết?
 Đã phân phối một cách rõ ràng tất cả các hành vi về các đối
tượng chưa?
 Các hành vi có được phân phối về đúng đối tượng không?
 Các interaction diagrams nằm ở đâu, mối quan hê gwiax chúng
có rõ ràng và phù hợp không?
Phân tích Use-Case
Dương Anh Đức
82
Review: Use-Case Analysis
 Mục tiêu của Use-Case Analysis là gì?
 Một analysis class là gì? Cho biết tên và mô tả về 3 analysis
stereotype.
 Use-case realization là gì?
 Mô tả một vài hoạt động khảo sát when đặt các trách nhiệm cho
các analysis class.
 Bao nhiêu interaction diagram phải được xây dựng trong giai
đoạn Use-Case Analysis?
Phân tích Use-Case
Dương Anh Đức
83
Exercise: Use-Case Analysis, Part 2
 Hãy cho biết các khái niệm sau:
 Các Requirements artifact, đặc biệt là đặc tả bổ sung
 Các cơ chế phân tích có thể
 Các flow of events interaction diagram cho một use case cụ
thể
 Với mỗi use case hãy xác định các dữ kiện sau:
 Các thuộc tính và các mối quan hệ của Analysis class
 Các cơ chế phân tích Analysis class
 Xây dựng các lược đồ sau:
 VOPC class diagram, chứa các analysis class, stereotype
của chúng, nhiệm vụ, các attribute, và relationship.
 Ánh xạ Analysis class với các cơ chế phân tích
Phân tích Use-Case
Dương Anh Đức
84