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 562 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 831,5 KB

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

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 objectoriented design communicates how the system needs to be coded.

Trang 1

Chapter 9:

Class and Method Design

Trang 2

PowerPoint Presentation for Dennis, Wixom, & Tegarden Systems Analysis and Design with UML, 3rd Edition

Copyright © 2009 John Wiley & Sons, Inc All rights reserved

• 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.

Trang 3

BASIC CHARACTERISTICS OF OBJECT ORIENTATION

Trang 4

PowerPoint Presentation for Dennis, Wixom, & Tegarden Systems Analysis and Design with UML, 3rd Edition

Copyright © 2009 John Wiley & Sons, Inc All rights reserved

Trang 5

Encapsulation & Info Hiding

• Hiding the content of the object from outside view

• Communication only through object’s

methods

• Key to reusability

Trang 6

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

Trang 7

Polymorphism Example

Trang 8

PowerPoint Presentation for Dennis, Wixom, & Tegarden Systems Analysis and Design with UML, 3rd Edition

Copyright © 2009 John Wiley & Sons, Inc All rights reserved

Trang 9

Rumbaugh’s Rules

1 Query operations should not be redefined

2 Methods that redefine inherited ones

should only restrict the semantics of the inherited ones

3 The underlying semantics of the inherited

method should never be changed

4 The signature (argument list) of the

inherited method should never be

changed

Trang 10

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

Trang 11

• Interdependency among modules

• Interaction coupling through message passing

Trang 12

PowerPoint Presentation for Dennis, Wixom, & Tegarden Systems Analysis and Design with UML, 3rd Edition

Copyright © 2009 John Wiley & Sons, Inc All rights reserved

Law of Demeter

Messages should be sent only by an object:

to itself

to objects contained in attributes of itself or a superclass

to an object that is passed as a parameter to the method

to an object that is created by the method

to an object that is stored in a global variable

Trang 13

Types of Interactive Coupling

Trang 14

PowerPoint Presentation for Dennis, Wixom, & Tegarden Systems Analysis and Design with UML, 3rd Edition

Cohesion

• “Single-mindedness of a module”

• Method cohesion

• Class cohesion

Trang 15

Types of Method Cohesion

Trang 16

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 Class Cohesion

Trang 17

• Creating the need to change another module

as a result of changing one

– Minimize overall connascence

– Minimize across encapsulation boundaries

– Maximize within encapsulation boundary

Trang 18

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 Connascence

Trang 19

OBJECT DESIGN ACTIVITIES

Trang 20

PowerPoint Presentation for Dennis, Wixom, & Tegarden Systems Analysis and Design with UML, 3rd Edition

Copyright © 2009 John Wiley & Sons, Inc All rights reserved

Additional Specification

• First review the current set of models

– Sufficient but only necessary classes to solve problem

– No missing attributes or methods

– No extraneous attributes or methods

• Examine visibility

Trang 21

Signatures for each method

• Name of the method

• Parameters or arguments to pass

• Type of value the method will return to the calling method

Trang 22

PowerPoint Presentation for Dennis, Wixom, & Tegarden Systems Analysis and Design with UML, 3rd Edition

Copyright © 2009 John Wiley & Sons, Inc All rights reserved

Trang 23

Identify Opportunities for Reuse

• Patterns

• Framework

• Class libraries

• Components

Trang 24

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

Trang 25

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

Trang 26

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

Trang 28

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

Trang 30

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

Trang 31

Sample Contract Form

Trang 32

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

Trang 33

Method Specification Syntax

• No formal syntax specification

• General information

• Events

• Message Passing

• Algorithm Specification

Trang 34

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

Trang 35

Pseudocode Example

(Get CD-info module)

Accept (CD_title) {Required}

Accept (CD_artist) {Required}

Accept (CD_category) {Required} Accept (CD_length)

Return

Trang 36

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

Ngày đăng: 16/05/2017, 13:42

TỪ KHÓA LIÊN QUAN

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

TÀI LIỆU LIÊN QUAN

w