oose13 - introduction to objects

Upload: faiz10march6456

Post on 30-May-2018

215 views

Category:

Documents


0 download

TRANSCRIPT

  • 8/14/2019 OOSE13 - Introduction to Objects

    1/39

    Slide 7.1

    The McGraw-Hill Companies, 2002

    Object-Oriented andClassical Software

    Engineering

    Fifth Edition, WCB/McGraw-Hill, 2002

    Stephen R. [email protected]

  • 8/14/2019 OOSE13 - Introduction to Objects

    2/39

    Slide 7.2

    The McGraw-Hill Companies, 2002

    CHAPTER 7

    INTRODUCTION TOOBJECTS

  • 8/14/2019 OOSE13 - Introduction to Objects

    3/39

    Slide 7.3

    The McGraw-Hill Companies, 2002

    Overview

    q What is a module?q Cohesionq Couplingq Data encapsulation product maintenance

    q Abstract data typesq Information hidingq Objectsq Inheritance, polymorphism and dynamic

    bindingq Cohesion and coupling of objects

  • 8/14/2019 OOSE13 - Introduction to Objects

    4/39

    Slide 7.4

    The McGraw-Hill Companies, 2002

    Introduction to Objects

    q What is a module?

    A lexically contiguous sequence of program statements,

    bounded by boundary elements, with an aggregate

    identifier

  • 8/14/2019 OOSE13 - Introduction to Objects

    5/39

    Slide 7.5

    The McGraw-Hill Companies, 2002

    Design of Computer

    q A highly incompetent

    computer architectdecides to build anALU, shifter and 16registers with AND,

    OR, and NOT gates,rather than NAND orNOR gates.

  • 8/14/2019 OOSE13 - Introduction to Objects

    6/39

    Slide 7.6

    The McGraw-Hill Companies, 2002

    Design of Computer (contd)

    q Architect designs

    3 silicon chips

  • 8/14/2019 OOSE13 - Introduction to Objects

    7/39

    Slide 7.7

    The McGraw-Hill Companies, 2002

    Design of Computer (contd)

    q Redesign

    with one gatetype per chip

    q Resultingmasterpiece

  • 8/14/2019 OOSE13 - Introduction to Objects

    8/39

  • 8/14/2019 OOSE13 - Introduction to Objects

    9/39

    Slide 7.9

    The McGraw-Hill Companies, 2002

    Composite/Structured Design

    q Method for breaking up a product into modules for

    Maximal interaction within module, and

    Minimal interaction between modules

    q Module cohesion

    Degree of interaction within a moduleq Module coupling

    Degree of interaction between modules

  • 8/14/2019 OOSE13 - Introduction to Objects

    10/39

    Slide 7.10

    The McGraw-Hill Companies, 2002

    Function, Logic, and Context of module

    q In C/SD, the name of a module is its function

    q Example

    Module computes square root of double precision

    integers using Newtons algorithm. Module is

    named compute square root

  • 8/14/2019 OOSE13 - Introduction to Objects

    11/39

    Slide 7.11

    The McGraw-Hill Companies, 2002

    Cohesion

    q Degree of interaction within a module

    q Seven categories or levels of cohesion

    (non-linear scale)

  • 8/14/2019 OOSE13 - Introduction to Objects

    12/39

    Slide 7.12

    The McGraw-Hill Companies, 2002

    1. Coincidental Cohesion

    q A module has coincidental cohesion if it performs

    multiple, completely unrelated actions

    q Example print next line, reverse string of characters comprising second

    parameter, add 7 to fifth parameter, convert fourth parameter to

    floating point

    q Arise from rules like

    Every module will consist of between 35 and 50

    statements

  • 8/14/2019 OOSE13 - Introduction to Objects

    13/39

    Slide 7.13

    The McGraw-Hill Companies, 2002

    Why Is Coincidental Cohesion So Bad?

    q Degrades maintainability

    q Modules are not reusable

    q This is easy to fix

    Break into separate modules each performing one task

  • 8/14/2019 OOSE13 - Introduction to Objects

    14/39

    Slide 7.14

    The McGraw-Hill Companies, 2002

    2. Logical Cohesion

    q A module has logical cohesion when it performs a series of

    related actions, one of which is selected by the callingmodule

    q Example 1

    function code = 7;

    new operation (op code, dummy 1, dummy 2, dummy3);

    // dummy 1, dummy 2, and dummy 3 are dummyvariables,

    // not used if function code is equal to 7

    q Example 2 Module performing all input and output

    q Example 3

    One version of OS/VS2 contained logical cohesion module

    performing 13 different actions. Interface contained 21 pieces ofdata

  • 8/14/2019 OOSE13 - Introduction to Objects

    15/39

    Slide 7.15

    The McGraw-Hill Companies, 2002

    Why Is Logical Cohesion So Bad?

    q The interface is difficult to understand

    q Code for more than one action may be intertwined

    q Difficult to reuse

  • 8/14/2019 OOSE13 - Introduction to Objects

    16/39

    Slide 7.16

    The McGraw-Hill Companies, 2002

    Why Is Logical Cohesion So Bad? (contd)

    q A new tape unit is installed

    q What is the effect on the laser printer?

  • 8/14/2019 OOSE13 - Introduction to Objects

    17/39

    Slide 7.17

    The McGraw-Hill Companies, 2002

    3. Temporal Cohesion

    q A module has temporal cohesion when it

    performs a series of actions related in time

    q Example open old master file, new master file, transaction file, print file,

    initialize sales district table, read first transaction record, read firstold master record (a.k.a. perform initialization)

  • 8/14/2019 OOSE13 - Introduction to Objects

    18/39

    Slide 7.18

    The McGraw-Hill Companies, 2002

    Why Is Temporal Cohesion So Bad?

    q Actions of this module are weakly related to

    one another, but strongly related to actions in

    other modules.

    Considersales district table

    q Not reusable

  • 8/14/2019 OOSE13 - Introduction to Objects

    19/39

    Slide 7.19

    The McGraw-Hill Companies, 2002

    4. Procedural Cohesion

    q A module has procedural cohesion if it

    performs a series of actions related by the

    procedure to be followed by the product

    q Example

    read part number and update repair record on master file

  • 8/14/2019 OOSE13 - Introduction to Objects

    20/39

    Slide 7.20

    The McGraw-Hill Companies, 2002

    Why Is Procedural Cohesion So Bad?

    q Actions are still weakly connected, so module is

    not reusable

  • 8/14/2019 OOSE13 - Introduction to Objects

    21/39

  • 8/14/2019 OOSE13 - Introduction to Objects

    22/39

  • 8/14/2019 OOSE13 - Introduction to Objects

    23/39

    Slide 7.23

    The McGraw-Hill Companies, 2002

    7. Informational Cohesion

    q A module has informational cohesion if it performs

    a number of actions, each with its own entry point,with independent code for each action, all

    performed on the same data structure

  • 8/14/2019 OOSE13 - Introduction to Objects

    24/39

    Slide 7.24

    The McGraw-Hill Companies, 2002

    Why Is Informational Cohesion So Good?

    q Essentially, this is an abstract data type(see later)

  • 8/14/2019 OOSE13 - Introduction to Objects

    25/39

    Slide 7.25

    The McGraw-Hill Companies, 2002

    7. Functional Cohesion

    q Module with functional cohesion performs

    exactly one action

    q Example 1 get temperature of furnace

    q Example 2 compute orbital of electron

    q

    Example 3 write to floppy disk

    q Example 4 calculate sales commission

  • 8/14/2019 OOSE13 - Introduction to Objects

    26/39

    Slide 7.26

    The McGraw-Hill Companies, 2002

    Why is functional cohesion so good?

    q More reusable

    q Corrective maintenance easier

    Fault isolation

    Fewer regression faults

    q Easier to extend product

  • 8/14/2019 OOSE13 - Introduction to Objects

    27/39

    Slide 7.27

    The McGraw-Hill Companies, 2002

    Cohesion Case Study

  • 8/14/2019 OOSE13 - Introduction to Objects

    28/39

    Slide 7.28

    The McGraw-Hill Companies, 2002

    Coupling

    q Degree of interaction between two modules

    q Five categories or levels of coupling

    (non-linear scale)

  • 8/14/2019 OOSE13 - Introduction to Objects

    29/39

    Slide 7.29

    The McGraw-Hill Companies, 2002

    1. Content Coupling

    q Two modules are content coupled if one

    directly references contents of the other

    q Example 1

    Module a modifies statement of module b

    q Example 2

    Module a refers to local data of module b in terms

    of some numerical displacement within b

    q Example 3

    Module a branches into local label of module b

  • 8/14/2019 OOSE13 - Introduction to Objects

    30/39

    Slide 7.30

    The McGraw-Hill Companies, 2002

    Why Is Content Coupling So Bad?

    q Almost any change to b, even recompiling b with

    new compiler or assembler, requires change to a

    q Warning

    Content coupling can be implemented in Ada through

    use of overlays implemented via address clauses

  • 8/14/2019 OOSE13 - Introduction to Objects

    31/39

    Slide 7.31

    The McGraw-Hill Companies, 2002

    2. Common Coupling

    q Two modules are common coupled if they have

    write access to global data

    q Example 1

    Modules cca and ccb can access and change value of

    global variable

  • 8/14/2019 OOSE13 - Introduction to Objects

    32/39

  • 8/14/2019 OOSE13 - Introduction to Objects

    33/39

    Slide 7.33

    The McGraw-Hill Companies, 2002

    Why Is Common Coupling So Bad?

    q Contradicts the spirit of structured programming

    The resulting code is virtually unreadable

    C C S ? ( )

  • 8/14/2019 OOSE13 - Introduction to Objects

    34/39

    Slide 7.34

    The McGraw-Hill Companies, 2002

    Why Is Common Coupling So Bad? (contd)

    q Modules can have side-effects

    This affects their readabilityq Entire module must be read to find out what it

    doesq Difficult to reuseq Module exposed to more data than necessary

  • 8/14/2019 OOSE13 - Introduction to Objects

    35/39

    Wh I C t l C li S B d?

  • 8/14/2019 OOSE13 - Introduction to Objects

    36/39

    Slide 7.36

    The McGraw-Hill Companies, 2002

    Why Is Control Coupling So Bad?

    q Modules are not independent; module b

    (the called module) must know internalstructure and logic of module a. Affects reusability

    q Associated with modules of logical

    cohesion

  • 8/14/2019 OOSE13 - Introduction to Objects

    37/39

    4 St C li ( td)

  • 8/14/2019 OOSE13 - Introduction to Objects

    38/39

    Slide 7.38

    The McGraw-Hill Companies, 2002

    4. Stamp Coupling (contd)

    q Two modules are stamp coupled if a data

    structure is passed as a parameter, but thecalled module operates on some but not all of

    the individual components of the data structure

    Wh I St C li S B d?

  • 8/14/2019 OOSE13 - Introduction to Objects

    39/39

    Slide 7.39Why Is Stamp Coupling So Bad?

    q It is not clear, without reading the entire module,

    which fields of a record are accessed or changed Example

    calculate withholding (employee record)q Difficult to understand

    q Unlikely to be reusableq More data than necessary is passed

    Uncontrolled data access can lead to computer crime

    q There is nothing wrong with passing a data structureas a parameter, provided allthe components of thedata structure are accessed and/or changed

    invert matrix (original matrix, inverted matrix);

    print inventory record (warehouse record);