LẬP TRÌNH HƯỚNG đối TƯỢNG bài 12 BIỂU đồ lớp - Pdf 31

8/24/2011

Mục đích
Mô tảkhung nhìn tĩnh của hệthống và cách
đưa nó vào trong một mô hình.
Minh họa cách đọc và hiểu một biểu đồlớp.
Mô hình hóa mối liên kết (association) và kết
tập (aggregation) và chỉra cách mô hình
chúng vào biểu đồlớp.
Mô hình tổng quát hóa (generalization) trên
một biểu đồlớp.

Bộ môn Công nghệ Phần mềm
Viện CNTT & TT
Trường Đại học Bách Khoa Hà Nội

k o?sqìmg?g ︰mf?I。h?s ︸mf
Bài 12. Biểu đồlớp

2

Nội dung
1.
2.
3.
4.

Nội dung

Biểu đồlớp (Class diagram)
Liên kết (Association)

5

6

1


8/24/2011

Mô tảphương thức

Phạm vi truy cập (Visibility)

operationName( [ direction] parameter:class,...) :returnType

private

public

protected

7

Phạm vi truy cập được biểu diễn như thế
nào?

8

Phạm vi (Scope)


# passed ([in] theCourseOffering : CourseOffering) : boolean
+ getNextAvailID () : int

11

12

2


8/24/2011

Biểu đồlớp (Class Diagram – CD)
Khung nhìn tĩnh của hệthống
CloseRegistrationForm

Schedule

Ví dụBiểu đồlớp
Có cách nào tốt hơn đểtổchức biểu đồlớp?

CloseRegistrationController

- semester
+ open()
+ close registration()

Student
+ get tuition()
+ add schedule()

- name
- employeeID : UniqueId
- hireDate
- status
- discipline
- maxLoad

CloseRegistrationForm

CloseRegistrationController

Professor
Student

+ submitFinalGrade()
+ acceptCourseOffering()
+ setMaxLoad()
+ takeSabbatical()
+ teachClass()

Course

CourseOffering

CourseCatalogSystem
BillingSystem
13

Gói (package)


Liên kế t ( Association)
Kết tập (Aggregation)
Tổng quát hóa (Generalization)

Student

17

Schedule

Course

18

3


8/24/2011

Biểu diễn bội sốquan hệ

Bội sốquan hệ(Multiplicity)

Unspecified
Exactly One

Professor

instructor


1.

1

Zero or More

19

Ví dụvềbội sốquan hệ

RegisterForCoursesForm

1

2.

RegistrationController

1

3.

0..1

4.

Biểu đồlớp (Class diagram)
Liên kết (Association)
Kế t tậ p ( Aggregation)
Tổng quát hóa (Generalization)

RegistrationController

1
0..1

0..1
1

Whole

Student

1
0..1

Schedule

0..*

Part
23

0..*

CourseOffering

0..4

24


public StudentRegistrar (){
(new RecordManager()).initialize();
}
}

27

Nội dung
1.
2.
3.
4.

28

Tổng quát hóa (Generalization)
Là mối liên hệ“là một loại” (“is a kind of”)

Biểu đồlớp (Class diagram)
Liên kết (Association)
Kết tập (Aggregation)
Tổ ng quát hóa
( Generalization)

29

30

5


Subclasses
(children)

+ communicate ()

+ communicate ()

- balance
- name
- number

Superclass
(parent)

Abstract class

Animal

All objects are either lions or tigers

Savings

31

Ví dụvềĐa kếthừa

FlyingThing

Checking
32

34

Tổng quát hóa: Thực thi đa hình
Animal
+ communicate ()

Lion
+ communicate ()

Without Polymorphism
if animal = “Lion” then
Lion communicate
else if animal = “Tiger” then
Tiger communicate
end

Tiger
+ communicate ()

With Polymorphism
Animal communicate

35

6




Nhờ tải bản gốc

Tài liệu, ebook tham khảo khác

Music ♫

Copyright: Tài liệu đại học © DMCA.com Protection Status