1. Trang chủ
  2. » Giáo Dục - Đào Tạo

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

6 356 0

Đang tải... (xem toàn văn)

THÔNG TIN TÀI LIỆU

Thông tin cơ bản

Định dạng
Số trang 6
Dung lượng 464,87 KB

Các công cụ chuyển đổi và chỉnh sửa cho tài liệu này

Nội dung

Biểu đồ lớp 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 ag

Trang 1

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

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.

2

Nội dung

3

Nội dung

4

1.1 Lớp (Class)

Class_Name

attribute1 attribute2 attribute3 method1() method2()

5

Biểu diễn thuộc tính

attributeName : Type = Default

6

Trang 2

Mô tảphương thức

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

7

private

Phạm vi truy cập (Visibility)

8

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

nào?

9

Class1

- privateAttribute

# protectedAttribute

- privateOperation ()

# protecteOperation ()

Phạm vi (Scope)

Class1

- classifierScopeAttr

- instanceScopeAttr + classifierScopeOp () + instanceScopeOp ()

10

Ví dụ: Scope

Student

- name

- address

- nextAvailID : int

+ addSchedule ([in] theSchedule : Schedule, [in] forSemester : Semester)

+ getSchedule ([in] forSemester : Semester) : Schedule

+ hasPrerequisites ([in] forCourseOffering : CourseOffering) : boolean

# passed ([in] theCourseOffering : CourseOffering) : boolean

+ getNextAvailID () : int

- studentID

1.2 Biểu đồlớp là gì?

Biểu đồ lớp chỉ ra sự tồn tại của các lớp

Trang 3

Biểu đồlớp (Class Diagram – CD)

Khung nhìn tĩnh của hệthống

13

CloseRegistrationForm

+ open()

+ close registration()

Student

+ get tuition()

+ add schedule()

+ get schedule()

+ delete schedule()

+ has pre-requisites()

Schedule

- semester

+ commit()

+ select alternate()

+ remove offering()

+ level()

+ cancel()

+ get cost()

+ delete()

+ submit()

+ save()

+ any conflicts?()

+ create with offerings()

+ update with new selections()

Professor

- name

- employeeID : UniqueId

- hireDate

- status

- discipline

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

CloseRegistrationController

+ is registration open?() + close registration()

Ví dụBiểu đồlớp

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

14

CloseRegistrationForm

LoginForm

Professor

BillingSystem

CloseRegistrationController

RegisterForCoursesForm

Course CourseCatalogSystem

Student

RegistrationController

CourseOffering Schedule

Gói (package)

University Artifacts

15

Ví dụ: Registration Package

16

Registration

CloseRegistrationForm CloseRegistrationController

RegisterForCoursesForm RegistrationController

Nội dung

17

Liên kết (association) là gì?

Mối liên hệngữ nghĩa giữa hai hay nhiều lớp

18

Course

Trang 4

Bội sốquan hệ(Multiplicity)

19

instructor

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

20

2 4 0 1 1 *

0 *

1

*

2, 4 6

Unspecified Exactly One Zero or More Zero or More

Zero or One (optional value)

One or More

Specified Range Multiple, Disjoint Ranges

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

21

RegisterForCoursesForm

CourseOffering Schedule

0 4 0 *

Student

0 *

1

RegistrationController 1

1

1

1

0 1

0 1

0 1

Nội dung

22

Kết tập (aggregation) là gì?

Là một dạng đặc biệt của liên kết mô hình

hóa mối quan hệ toàn thể-bộphận

(whole-part)

Part Whole 1

Ví dụvềkết tập

RegisterForCoursesForm

CourseOffering Schedule

0 4 0 *

Student

0 *

1

RegistrationController 1

1

1

1

0 1

0 1

0 1

Trang 5

Cấu thành (Composition) là gì?

Whole

Composition

Part

Part Whole

25

Association, Aggregation and Composition Mối quan hệgiữa các lớp

(relationship)

26

Ví dụ– Association

public class StudentRegistrar {

public StudentRegistrar (){

(new RecordManager()).initialize();

}

}

27

Ví dụ– Aggregration vs Composition

28

Nội dung

( Generalization)

29

Tổng quát hóa (Generalization)

Là mối liên hệ“là một loại” (“is a kind of”)

30

Trang 6

There are no direct instances of Animal

Animal + communicate ()

+ communicate () + communicate ()

Lớp trừu tượng và lớp cụthể

(Abstract and Concrete Class)

31

All objects are either lions or tigers

Abstract class Abstract operation

Communication

Discriminator

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

32

Checking Savings

Superclass (parent)

Subclasses (children)

Generalization Relationship

Descendents

Ancestor

Account

- balance

- name

- number + withdraw() + createStatement()

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

33

Horse Wolf

Bird Helicopter

Airplane

Multiple Inheritance

OO Principle:

Encapsulation

Đa hình (Polymorphism) là gì?

34

Remote Control

Tổng quát hóa: Thực thi đa hình

Without Polymorphism

if animal = “Lion” then

Lion communicate

else if animal = “Tiger” then

Tiger communicate

With Polymorphism

Animal communicate

Animal + communicate ()

+ communicate () + communicate ()

Ngày đăng: 11/11/2015, 11:54

TỪ KHÓA LIÊN QUAN