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

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

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

Thông tin tài liệu

8/24/2011 Mục đích Mô tảkhung nhìn tĩnh hệthống cách đưa vào mô hình Minh họa cách đọc hiểu biểu đồlớp Mô hình hóa mối liên kết (association) kết tập (aggregation) 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) 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 Nội dung Nội dung Biểu đồlớp (Class diagram) Liên kết (Association) Kết tập (Aggregation) Tổng quát hóa (Generalization) Biể u đồ lớ p ( Class diagram) Liên kết (Association) Kết tập (Aggregation) Tổng quát hóa (Generalization) 1.1 Lớp (Class) Biểu diễn thuộc tính attributeName : Type = Default Class_Name attribute1 attribute2 attribute3 method1() method2() method3() 8/24/2011 Mô tảphương thức Phạm vi truy cập (Visibility) operationName( [ direction] parameter:class, ) :returnType private public protected Phạm vi truy cập biểu diễn nào? Phạm vi (Scope) Class1 - privateAttribute + publicAttribute # protectedAttribute - privateOperation () + publicOPeration () # protecteOperation () Class1 - classifierScopeAttr - instanceScopeAttr + classifierScopeOp () + instanceScopeOp () 10 Ví dụ: Scope 1.2 Biểu đồlớp gì? Biểu đồ lớp tồn lớp Student - name - address - studentID - 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 11 12 8/24/2011 Biểu đồlớp (Class Diagram – CD) Khung nhìn tĩnh hệthống CloseRegistrationForm Schedule Ví dụBiểu đồlớp Có cách tốt đểtổchức biểu đồlớp? CloseRegistrationController - semester + open() + close registration() Student + get tuition() + add schedule() + get schedule() + delete schedule() + has pre-requisites() + commit() + select alternate() + remove offering() + level() + cancel() + get cost() + delete() + submit() + save() + any conflicts?() + create with offerings() + update with new selections() LoginForm + is registration open?() + close registration() RegistrationController RegisterForCoursesForm Professor 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) 14 Ví dụ: Registration Package Registration CloseRegistrationForm CloseRegistrationController RegisterForCoursesForm RegistrationController University Artifacts 15 Nội dung 16 Liên kết (association) gì? Mối liên hệngữnghĩa hai hay nhiều lớp Biểu đồlớp (Class diagram) Liên kế t ( Association) Kết tập (Aggregation) Tổng quát hóa (Generalization) Student 17 Schedule Course 18 8/24/2011 Biểu diễn bội sốquan hệ Bội sốquan hệ(Multiplicity) Unspecified Exactly One Professor instructor CourseOffering * * Zero or More * One or More * Zero or One (optional value) Specified Range Multiple, Disjoint Ranges 2, 20 Nội dung 1 Zero or More 19 Ví dụvềbội sốquan hệ RegisterForCoursesForm RegistrationController Biểu đồlớp (Class diagram) Liên kết (Association) Kế t tậ p ( Aggregation) Tổng quát hóa (Generalization) 1 Student Schedule * * CourseOffering 22 21 Kết tập (aggregation) gì? Ví dụvềkết tập Là dạng đặc biệt liên kết mô hình hóa mối quan hệtoàn thể-bộphận (wholepart) RegisterForCoursesForm RegistrationController 1 1 Whole Student 1 Schedule * Part 23 * CourseOffering 24 8/24/2011 Cấu thành (Composition) gì? Association, Aggregation and Composition Mối quan hệgiữa lớp (relationship) Part Whole Whole Part Composition 26 25 Ví dụ– Association Ví dụ– Aggregration vs Composition public class StudentRegistrar { public StudentRegistrar (){ (new RecordManager()).initialize(); } } 27 Nội dung 28 Tổng quát hóa (Generalization) Là mối liên hệ“là 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 8/24/2011 Lớp trừu tượng lớp cụthể (Abstract and Concrete Class) Ví dụvềĐơn kếthừa Ancestor Account Discriminator Abstract operation + communicate () Communication + withdraw() + createStatement() Generalization Relationship There are no direct instances of Animal Lion Tiger 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 Descendents Đa hình (Polymorphism) gì? Animal Multiple Inheritance Airplane Helicopter Bird Wolf Horse Manufacturer A Manufacturer B Manufacturer C OO Principle: Encapsulation 33 Remote Control 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 ... getNextAvailID () : int 11 12 8/24/2011 Biểu đ lớp (Class Diagram – CD) Khung nhìn tĩnh hệthống CloseRegistrationForm Schedule Ví d Biểu đ lớp Có cách tốt đểtổchức biểu đ lớp? CloseRegistrationController... instanceScopeAttr + classifierScopeOp () + instanceScopeOp () 10 Ví dụ: Scope 1.2 Biểu đ lớp gì? Biểu đồ lớp tồn lớp Student - name - address - studentID - nextAvailID : int + addSchedule ([in]... hệ“là 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 8/24/2011 Lớp trừu tượng lớp cụthể (Abstract and Concrete

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

Từ khóa liên quan

Tài liệu cùng người dùng

  • Đang cập nhật ...

Tài liệu liên quan