1. Trang chủ
  2. » Công Nghệ Thông Tin

Lecture Systems analysis and design with UML (3/e) - Chapter 9: Class and method design

36 73 0

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

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

THÔNG TIN TÀI LIỆU

Thông tin cơ bản

Định dạng
Số trang 36
Dung lượng 518,29 KB

Nội dung

This chapter presents a set of criteria, activities, and techniques used to design classes and methods. Together they are used to ensure the object-oriented design communicates how the system needs to be coded.

Chapter 9: Class and Method Design PowerPoint Presentation for Dennis, Wixom, & Tegarden Systems Analysis and Design with UML, 3rd Edition Copyright © 2009 John Wiley & Sons, Inc All rights reserved Objectives • Become familiar with coupling, cohesion, and connascence • Be able to specify, restructure, and optimize object designs • Be able to identify the reuse of predefined classes, libraries, frameworks, and components • Be able to specify constraints and contracts • Be able to create a method specification PowerPoint Presentation for Dennis, Wixom, & Tegarden Systems Analysis and Design with UML, 3rd Edition Copyright © 2009 John Wiley & Sons, Inc All rights reserved BASIC CHARACTERISTICS OF OBJECT ORIENTATION PowerPoint Presentation for Dennis, Wixom, & Tegarden Systems Analysis and Design with UML, 3rd Edition Copyright © 2009 John Wiley & Sons, Inc All rights reserved Elements of OOSAD • • • • • • Classes Objects Attributes States Methods Messages PowerPoint Presentation for Dennis, Wixom, & Tegarden Systems Analysis and Design with UML, 3rd Edition Copyright © 2009 John Wiley & Sons, Inc All rights reserved Encapsulation & Info Hiding • Hiding the content of the object from outside view • Communication only through object’s methods • Key to reusability PowerPoint Presentation for Dennis, Wixom, & Tegarden Systems Analysis and Design with UML, 3rd Edition Copyright © 2009 John Wiley & Sons, Inc All rights reserved Polymorphism & Dynamic Binding • Same message triggers different methods in different objects • Dynamic binding means specific method is selected at run time • Implementation of dynamic binding is language specific • Need to be very careful about run time errors • Need to ensure semantic consistency PowerPoint Presentation for Dennis, Wixom, & Tegarden Systems Analysis and Design with UML, 3rd Edition Copyright © 2009 John Wiley & Sons, Inc All rights reserved Polymorphism Example PowerPoint Presentation for Dennis, Wixom, & Tegarden Systems Analysis and Design with UML, 3rd Edition Copyright © 2009 John Wiley & Sons, Inc All rights reserved Inheritance • Single inheritance one parent class • Multiple inheritance multiple parent classes • Redefinition and inheritance conflict • Most inheritance conflicts are due to poor classification PowerPoint Presentation for Dennis, Wixom, & Tegarden Systems Analysis and Design with UML, 3rd Edition Copyright © 2009 John Wiley & Sons, Inc All rights reserved Rumbaugh’s Rules Query operations should not be redefined Methods that redefine inherited ones should  only restrict the semantics of the inherited ones The underlying semantics of the inherited  method should never be changed The signature (argument list) of the inherited  method should never be changed PowerPoint Presentation for Dennis, Wixom, & Tegarden Systems Analysis and Design with UML, 3rd Edition Copyright © 2009 John Wiley & Sons, Inc All rights reserved DESIGN CRITERIA PowerPoint Presentation for Dennis, Wixom, & Tegarden Systems Analysis and Design with UML, 3rd Edition Copyright © 2009 John Wiley & Sons, Inc All rights reserved Define constraints • • • • Pre-conditions Post conditions Invariants How to handle violations (exceptions in C+ + and Java)? PowerPoint Presentation for Dennis, Wixom, & Tegarden Systems Analysis and Design with UML, 3rd Edition Copyright © 2009 John Wiley & Sons, Inc All rights reserved Identify Opportunities for Reuse • • • • Patterns Framework Class libraries Components PowerPoint Presentation for Dennis, Wixom, & Tegarden Systems Analysis and Design with UML, 3rd Edition Copyright © 2009 John Wiley & Sons, Inc All rights reserved Restructure the Design • • • • Factoring Map design to current language Normalization Assure all inheritance relationships support only generalization/specialization semantics PowerPoint Presentation for Dennis, Wixom, & Tegarden Systems Analysis and Design with UML, 3rd Edition Copyright © 2009 John Wiley & Sons, Inc All rights reserved Optimizing the Design • • • • Review access paths Review attributes of each class Review direct and indirect fan-out Consider execution order of statements in often-used methods • Avoid re-computation by creating derived attributes and triggers PowerPoint Presentation for Dennis, Wixom, & Tegarden Systems Analysis and Design with UML, 3rd Edition Copyright © 2009 John Wiley & Sons, Inc All rights reserved CONSTRAINTS AND CONTRACTS PowerPoint Presentation for Dennis, Wixom, & Tegarden Systems Analysis and Design with UML, 3rd Edition Copyright © 2009 John Wiley & Sons, Inc All rights reserved Types of Constraints • Precondition Must be true before the method executes • Post-condition Must be true after the method finishes • Invariant Must always be true PowerPoint Presentation for Dennis, Wixom, & Tegarden Systems Analysis and Design with UML, 3rd Edition Copyright © 2009 John Wiley & Sons, Inc All rights reserved Invariants on a Class Diagram PowerPoint Presentation for Dennis, Wixom, & Tegarden Systems Analysis and Design with UML, 3rd Edition Copyright © 2009 John Wiley & Sons, Inc All rights reserved Contracts • Contracts document message passing between object • A contract is created for each method that is publicly visible in a class • Should contain enough information for the programmer to understand what the method is supposed to PowerPoint Presentation for Dennis, Wixom, & Tegarden Systems Analysis and Design with UML, 3rd Edition Copyright © 2009 John Wiley & Sons, Inc All rights reserved Elements of a Contract PowerPoint Presentation for Dennis, Wixom, & Tegarden Systems Analysis and Design with UML, 3rd Edition Copyright © 2009 John Wiley & Sons, Inc All rights reserved Sample Contract Form PowerPoint Presentation for Dennis, Wixom, & Tegarden Systems Analysis and Design with UML, 3rd Edition Copyright © 2009 John Wiley & Sons, Inc All rights reserved METHOD SPECIFICATION PowerPoint Presentation for Dennis, Wixom, & Tegarden Systems Analysis and Design with UML, 3rd Edition Copyright © 2009 John Wiley & Sons, Inc All rights reserved Method Specification Syntax • • • • • No formal syntax specification General information Events Message Passing Algorithm Specification PowerPoint Presentation for Dennis, Wixom, & Tegarden Systems Analysis and Design with UML, 3rd Edition Copyright © 2009 John Wiley & Sons, Inc All rights reserved Structured English PowerPoint Presentation for Dennis, Wixom, & Tegarden Systems Analysis and Design with UML, 3rd Edition Copyright © 2009 John Wiley & Sons, Inc All rights reserved Pseudocode Example (Get CD­info module) Accept (CD_title) {Required} Accept (CD_artist) {Required} Accept (CD_category) {Required} Accept (CD_length) Return PowerPoint Presentation for Dennis, Wixom, & Tegarden Systems Analysis and Design with UML, 3rd Edition Copyright © 2009 John Wiley & Sons, Inc All rights reserved Summary • • • • • Basic Characteristics of Object Orientation Design Criteria Object Design Activities Constraints and Contracts Method Specification PowerPoint Presentation for Dennis, Wixom, & Tegarden Systems Analysis and Design with UML, 3rd Edition Copyright © 2009 John Wiley & Sons, Inc All rights reserved ... Design with UML, 3rd Edition Copyright © 2009 John Wiley & Sons, Inc All rights reserved DESIGN CRITERIA PowerPoint Presentation for Dennis, Wixom, & Tegarden Systems Analysis and Design with UML, ... Tegarden Systems Analysis and Design with UML, 3rd Edition Copyright © 2009 John Wiley & Sons, Inc All rights reserved Cohesion • “Single-mindedness of a module” • Method cohesion • Class cohesion... • Pre-conditions Post conditions Invariants How to handle violations (exceptions in C+ + and Java)? PowerPoint Presentation for Dennis, Wixom, & Tegarden Systems Analysis and Design with UML,

Ngày đăng: 15/05/2020, 22:28

TỪ KHÓA LIÊN QUAN

TÀI LIỆU CÙNG NGƯỜI DÙNG

TÀI LIỆU LIÊN QUAN