Software Engineering - Lecture 7: Object Oriented Design

Gán trách nhiệm cho các đối tượng • Design Principles • Expert Doer • High Cohesion • Low Coupling • Business Policies • Class Diagram

pdf11 trang | Chia sẻ: thuongdt324 | Lượt xem: 443 | Lượt tải: 0download
Bạn đang xem nội dung tài liệu Software Engineering - Lecture 7: Object Oriented Design, để tải tài liệu về máy bạn click vào nút DOWNLOAD ở trên
Ivan Marsic Rutgers University LECTURE 7: Object Oriented Design 2Topics • Gán trách nhiệm cho các đối tượng • Design Principles • Expert Doer • High Cohesion • Low Coupling • Business Policies • Class Diagram 3select function(“unlock") : System User «initiating actor» prompt for the key enter key verify key signal: valid key, lock open open the lock, turn on the light Timer «offstage actor» start ("duration“) System Sequence Diagrams considered interactions between the actors Biểu đồ tuần tự hệ thống cho usecase mở khóa System Sequence Diagrams 4Design: Object Interactions • System Sequence Diagram mô tả tương tác giữa các actor • Object Sequence Diagram mô tả tương tác giữa các đối tượng checkKey() sk := getNext() setOpen(true) : Checker : KeyStorage val == null : setLit(true) alt val != null [else] Controller : LockCtrl select function(“unlock") : System User «initiating actor» prompt for the key enter key verify key signal: valid key, lock open open the lock, turn on the light Timer «offstage actor» start ("duration“) ystem System Sequence Diagram Design Sequence Diagram 5Metaphor for Software Design: “Connecting the Dots” :Notifier:DatabaseConn Database LandlordResident :Archiver:Controller:SearchRequest:InterfacePage :PageMaker :InvestigRequest Ta bắt đầu từ các đối tượng/khái niệm từ pha phân tích, và sửa hoặc thêm các đối tượng mới, nhằm làm cho hệ thống hoạt động được. 6Types of Object Responsibilities • Knowing responsibility: ghi nhớ dữ liệu hoặc tham chiếu, chẳng hạn data values, data collections, tham chiếu tới các đối tượng khác. Biểu diễn ở dạng thuộc tính • Doing responsibility: thực hiện tính toán, chẳng hạn xử lý dữ liệu, điều khiển các thiết bị phần cứng, biểu diễn dưới dạng phương thức • Communicating responsibility: Liên lạc với các đối tượng khác, thể hiện ở việc gọi phương thức của đối tượng khác 7Design: Assigning Responsibilities (a) (b) : PageMaker: DatabaseConn accessList := retrieve(params : string) interfacePage := render(accessList : string) ? ? R1. R2. checkKey() : Checker : DeviceCtrl ? : Controller activate( "lock" ) 8Đặc điểm của thiết kế tốt • Chuỗi liên lạc ngắn • Phân công công việc cân bằng • Ít quan hệ giữa các lớp method_1() method_2() method_N() method_1() 9Design Principles • Expert Doer Principle: ai biết thông tin thì làm • High Cohesion Principle: không giữ nhiều trách nhiệm • Low Coupling Principle: không giữ quá nhiều communication responsibility There are many more 10 Cohesion Low cohesion High cohesion 11 Class Diagram Base Class Container KeyChecker + checkKey(k : Key) : boolean – compare(k : Key, sk : Key) : boolean Key – code_ : string – timestamp_ : long – doorLocation_ : string KeyStorage + getNext() : Key Logger + logTransaction(k : Key) Controller # numOfAttemps_ : long # maxNumOfAttempts_ : long + enterKey(k : Key) – denyMoreAttempts() 1 1 sensor logger 11..* validKeys 1 1 devCtrl DeviceCtrl # devStatuses_ : Vector + activate(dev : string) : boolean + deactivate(dev :string) : boolean + getStatus(dev : string) : Object PhotoSObsrv + isDaylight() : boolean 1 checker
Tài liệu liên quan