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

Seventh Edition - Chương 7 pptx

93 321 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

Slide 7.1 © The McGraw-Hill Companies, 2007 Object-Oriented and Classical Software Engineering Seventh Edition, WCB/McGraw-Hill, 2007 Stephen R. Schach srs@vuse.vanderbilt.edu Slide 7.2 © The McGraw-Hill Companies, 2007 CHAPTER 7 FROM MODULES TO OBJECTS Slide 7.3 © The McGraw-Hill Companies, 2007 Overview  What is a module?  Cohesion  Coupling  Data encapsulation  Abstract data types  Information hiding  Objects  Inheritance, polymorphism, and dynamic binding  The object-oriented paradigm Slide 7.4 © The McGraw-Hill Companies, 2007 7.1 What Is a Module?  A lexically contiguous sequence of program statements, bounded by boundary elements, with an aggregate identifier  “Lexically contiguous”  Adjoining in the code  “Boundary elements”  { }  begin end  “Aggregate identifier”  A name for the entire module Slide 7.5 © The McGraw-Hill Companies, 2007 Design of Computer  A highly incompetent computer architect decides to build an ALU, shifter, and 16 registers with AND, OR, and NOT gates, rather than NAND or NOR gates Figure 7.1 Slide 7.6 © The McGraw-Hill Companies, 2007 Design of Computer (contd)  The architect designs three silicon chips Figure 7.2 Slide 7.7 © The McGraw-Hill Companies, 2007 Design of Computer (contd)  Redesign with one gate type per chip  Resulting “masterpiec e” Figure 7.3 Slide 7.8 © The McGraw-Hill Companies, 2007 Computer Design (contd)  The two designs are functionally equivalent  The second design is  Hard to understand  Hard to locate faults  Difficult to extend or enhance  Cannot be reused in another product  Modules must be like the first design  Maximal relationships within modules, and  Minimal relationships between modules Slide 7.9 © The McGraw-Hill Companies, 2007 Composite/Structured Design  A method for breaking up a product into modules to achieve  Maximal interaction within a module, and  Minimal interaction between modules  Module cohesion  Degree of interaction within a module  Module coupling  Degree of interaction between modules Slide 7.10 © The McGraw-Hill Companies, 2007 Function, Logic, and Context of a Module  In C/SD, the name of a module is its function  Example:  A module computes the square root of double precision integers using Newton’s algorithm. The module is named compute_square_root  The underscores denote that the classical paradigm is used here [...]... McGraw-Hill Companies, 20 07 Why Is Informational Cohesion So Good? Slide 7. 28 Figure 7. 6  Essentially, this is an abstract data type (see later) © The McGraw-Hill Companies, 20 07 7.2.8 Cohesion Example © The McGraw-Hill Companies, 20 07 Slide 7. 29 Figure 7. 7 7. 3 Coupling  Slide 7. 30 The degree of interaction between two modules Five categories or levels of coupling (non-linear scale) Figure 7. 8 ©... The McGraw-Hill Companies, 20 07 Why Is Logical Cohesion So Bad? Slide 7. 16  The interface is difficult to understand  Code for more than one action may be intertwined  Difficult to reuse © The McGraw-Hill Companies, 20 07 Why Is Logical Cohesion So Bad? (contd) Slide 7. 17  A new tape unit is installed What is the effect on the laser printer? Figure 7. 5 © The McGraw-Hill Companies, 20 07 7.2.3 Temporal... write_to_diskette  Example 4:  calculate_sales_commission © The McGraw-Hill Companies, 20 07 Slide 7. 25 Why Is Functional Cohesion So Good? Slide 7. 26  More reusable  Corrective maintenance is easier  Fault isolation  Fewer regression faults  Easier to extend a product © The McGraw-Hill Companies, 20 07 7.2 .7 Informational Cohesion  Slide 7. 27 A module has informational cohesion if it performs a number... assembler, requires a change to module © The McGraw-Hill Companies, 20 07 Slide 7. 32 p 7. 3.2 Common Coupling Slide 7. 33  Two modules are common coupled if they have write access to global data  Example 1 Figure 7. 9  Modules cca and ccb can access and change the value of global_variable © The McGraw-Hill Companies, 20 07 7.3.2 Common Coupling (contd)  Slide 7. 34 Example 2:  Modules cca and ccb both have... calculate_new_coordinates_and_send_them_to_terminal © The McGraw-Hill Companies, 20 07 Why Is Communicational Cohesion So Bad? Slide 7. 23  Still lack of reusability © The McGraw-Hill Companies, 20 07 7.2.6 Functional Cohesion  Slide 7. 24 A module with functional cohesion performs exactly one action © The McGraw-Hill Companies, 20 07 7.2.6 Functional Cohesion  Example 1:  get_temperature_of_furnace  Example... COBOL common (nonstandard)  COBOL-80 global © The McGraw-Hill Companies, 20 07 Why Is Common Coupling So Bad?  It contradicts the spirit of structured programming The resulting code is virtually unreadable What causes this loop to terminate? Figure 7. 10 © The McGraw-Hill Companies, 20 07 Slide 7. 35 Why Is Common Coupling So Bad? (contd) Slide 7. 36  Modules can have side-effects  This affects their... sales_district_table  Not reusable © The McGraw-Hill Companies, 20 07 Slide 7. 19 7. 2.4 Procedural Cohesion Slide 7. 20  A module has procedural cohesion if it performs a series of actions related by the procedure to be followed by the product  Example:  read_part_number_and_update_repair_record_on_ master_file © The McGraw-Hill Companies, 20 07 Why Is Procedural Cohesion So Bad?  Slide 7. 21 The actions are still weakly.. .7. 2 Cohesion Slide 7. 11  The degree of interaction within a module  Seven categories or levels of cohesion (nonlinear scale) Figure 7. 4 © The McGraw-Hill Companies, 20 07 7.2.1 Coincidental Cohesion Slide 7. 12  A module has coincidental cohesion if it performs multiple, completely unrelated actions  Example:  print_next_line, reverse_string_of_characters_comprising_second_ parameter, add _7_ to_fifth_parameter,... of between 35 and 50 statements” © The McGraw-Hill Companies, 20 07 Why Is Coincidental Cohesion So Bad? Slide 7. 13  It degrades maintainability  A module with coincidental cohesion is not reusable  The problem is easy to fix  Break the module into separate modules, each performing one task © The McGraw-Hill Companies, 20 07 7.2.2 Logical Cohesion  Slide 7. 14 A module has logical cohesion when it... McGraw-Hill Companies, 20 07 7.3.1 Content Coupling Slide 7. 31  Two modules are content coupled if one directly references contents of the other  Example 1:  Module p modifies a statement of module q  Example 2:  Module p refers to local data of module q in terms of some numerical displacement within q  Example 3:  Module p branches into a local label of module q © The McGraw-Hill Companies, 2007 . Slide 7. 1 © The McGraw-Hill Companies, 20 07 Object-Oriented and Classical Software Engineering Seventh Edition, WCB/McGraw-Hill, 20 07 Stephen R. Schach srs@vuse.vanderbilt.edu Slide 7. 2 ©. gates Figure 7. 1 Slide 7. 6 © The McGraw-Hill Companies, 20 07 Design of Computer (contd)  The architect designs three silicon chips Figure 7. 2 Slide 7. 7 © The McGraw-Hill Companies, 20 07 Design. here Slide 7. 11 © The McGraw-Hill Companies, 20 07 7.2 Cohesion  The degree of interaction within a module  Seven categories or levels of cohesion (non- linear scale) Figure 7. 4 Slide 7. 12 © The

Ngày đăng: 01/08/2014, 14:20

Xem thêm: Seventh Edition - Chương 7 pptx

Mục lục

    7.1 What Is a Module?

    Design of Computer (contd)

    Function, Logic, and Context of a Module

    Why Is Coincidental Cohesion So Bad?

    Why Is Logical Cohesion So Bad?

    Why Is Logical Cohesion So Bad? (contd)

    Why Is Temporal Cohesion So Bad?

    Why Is Procedural Cohesion So Bad?

    Why Is Communicational Cohesion So Bad?

    Why Is Functional Cohesion So Good?

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

TÀI LIỆU LIÊN QUAN

w