se7_ch07_v07

download se7_ch07_v07

of 93

Transcript of se7_ch07_v07

  • 8/14/2019 se7_ch07_v07

    1/93

    Slide 7.1

    The McGraw-Hill Companies, 2007

    Object-Oriented andClassical Software

    Engineering

    Seventh Edition, WCB/McGraw-Hill, 2007

    Stephen R. [email protected]

  • 8/14/2019 se7_ch07_v07

    2/93

    Slide 7.2

    The McGraw-Hill Companies, 2007

    CHAPTER 7

    FROM MODULES

    TO OBJECTS

  • 8/14/2019 se7_ch07_v07

    3/93

    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

  • 8/14/2019 se7_ch07_v07

    4/93

    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

  • 8/14/2019 se7_ch07_v07

    5/93

    Slide 7.5

    The McGraw-Hill Companies, 2007

    Design of Computer

    A highly incompetent

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

    OR, and NOT gates,rather than NAND orNOR gates

    Figure 7.1

  • 8/14/2019 se7_ch07_v07

    6/93

    Slide 7.6

    The McGraw-Hill Companies, 2007

    Design of Computer (contd)

    The architect

    designs three

    silicon chips

    Figure 7.2

  • 8/14/2019 se7_ch07_v07

    7/93

    Slide 7.7

    The McGraw-Hill Companies, 2007

    Design of Computer (contd)

    Redesign with

    one gate typeper chip

    Resultingmasterpiece

    Figure 7.3

  • 8/14/2019 se7_ch07_v07

    8/93

    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, andMinimal relationships between modules

  • 8/14/2019 se7_ch07_v07

    9/93

    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

  • 8/14/2019 se7_ch07_v07

    10/93

    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 Newtons algorithm. The module isnamed compute_square_root

    The underscores denote that the classical

    paradigm is used here

  • 8/14/2019 se7_ch07_v07

    11/93

    Slide 7.11

    The McGraw-Hill Companies, 2007

    7.2 Cohesion

    The degree of interaction within a module

    Seven categories or levels of cohesion (non-linear

    scale)

    Figure 7.4

  • 8/14/2019 se7_ch07_v07

    12/93

    Slide 7.12

    The McGraw-Hill Companies, 2007

    7.2.1 Coincidental Cohesion

    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,

    convert_fourth_parameter_to_ floating_point

    Such modules arise from rules likeEvery module will consist of between 35 and 50

    statements

  • 8/14/2019 se7_ch07_v07

    13/93

    Slide 7.13

    The McGraw-Hill Companies, 2007

    Why Is Coincidental Cohesion So Bad?

    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

  • 8/14/2019 se7_ch07_v07

    14/93

    Slide 7.14

    The McGraw-Hill Companies, 2007

    7.2.2 Logical Cohesion

    A module has logical cohesion when it performs a

    series of related actions, one of which is selectedby the calling module

  • 8/14/2019 se7_ch07_v07

    15/93

    Slide 7.15

    The McGraw-Hill Companies, 2007

    Logical Cohesion (contd)

    Example 1:function_code = 7;new_operation (op code, dummy_1, dummy_2, dummy_3);

    // dummy_1, dummy_2, and dummy_3 are dummy variables,

    // not used if function code is equal to 7

    Example 2:An object performing all input and output

    Example 3:One version of OS/VS2 contained a module with logical

    cohesion performing 13 different actions. The interfacecontains 21 pieces of data

  • 8/14/2019 se7_ch07_v07

    16/93

  • 8/14/2019 se7_ch07_v07

    17/93

    Slide 7.17

    The McGraw-Hill Companies, 2007

    Why Is Logical Cohesion So Bad? (contd)

    A new tape unit is installed

    What is the effect on the laser printer?

    Figure 7.5

  • 8/14/2019 se7_ch07_v07

    18/93

    Slide 7.18

    The McGraw-Hill Companies, 2007

    7.2.3 Temporal Cohesion

    A module has temporal cohesion when it performs

    a series of actions related in time

    Example:

    open_old_master_file, new_master_file,transaction_file, and print_file;

    initialize_sales_district_table,

    read_first_transaction_record,

    read_first_old_master_record (a.k.a.

    perform_initialization)

  • 8/14/2019 se7_ch07_v07

    19/93

    Slide 7.19

    The McGraw-Hill Companies, 2007

    Why Is Temporal Cohesion So Bad?

    The actions of this module are weakly related to

    one another, but strongly related to actions in

    other modulesConsider sales_district_table

    Not reusable

  • 8/14/2019 se7_ch07_v07

    20/93

    Slide 7.20

    The McGraw-Hill Companies, 2007

    7.2.4 Procedural Cohesion

    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

  • 8/14/2019 se7_ch07_v07

    21/93

    Slide 7.21

    The McGraw-Hill Companies, 2007

    Why Is Procedural Cohesion So Bad?

    The actions are still weakly connected, so the

    module is not reusable

  • 8/14/2019 se7_ch07_v07

    22/93

    Slide 7.22

    The McGraw-Hill Companies, 2007

    7.2.5 Communicational Cohesion

    A module has communicational cohesion if it

    performs a series of actions related by theprocedure to be followed by the product, but in

    addition all the actions operate on the same data

    Example 1:update_record_in_database_and_write_it_to_audit_trail

    Example 2:calculate_new_coordinates_and_send_them_to_terminal

  • 8/14/2019 se7_ch07_v07

    23/93

    Slide 7.23

    The McGraw-Hill Companies, 2007

    Why Is Communicational Cohesion So Bad?

    Still lack of reusability

  • 8/14/2019 se7_ch07_v07

    24/93

    Slide 7.24

    The McGraw-Hill Companies, 2007

    7.2.6 Functional Cohesion

    A module with functional cohesion performs

    exactly one action

  • 8/14/2019 se7_ch07_v07

    25/93

    Slide 7.25

    The McGraw-Hill Companies, 2007

    7.2.6 Functional Cohesion

    Example 1: get_temperature_of_furnace

    Example 2: compute_orbital_of_electron

    Example 3: write_to_diskette

    Example 4: calculate_sales_commission

  • 8/14/2019 se7_ch07_v07

    26/93

    Slide 7.26

    The McGraw-Hill Companies, 2007

    Why Is Functional Cohesion So Good?

    More reusable

    Corrective maintenance is easier

    Fault isolation

    Fewer regression faults

    Easier to extend a product

  • 8/14/2019 se7_ch07_v07

    27/93

    Slide 7.27

    The McGraw-Hill Companies, 2007

    7.2.7 Informational Cohesion

    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 se7_ch07_v07

    28/93

    Slide 7.28

    The McGraw-Hill Companies, 2007

    Why Is Informational Cohesion So Good?

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

    Figure 7.6

  • 8/14/2019 se7_ch07_v07

    29/93

    Slide 7.29

    The McGraw-Hill Companies, 2007

    7.2.8 Cohesion Example

    Figure 7.7

  • 8/14/2019 se7_ch07_v07

    30/93

    Slide 7.30

    The McGraw-Hill Companies, 2007Figure 7.8

    7.3 Coupling

    The degree of interaction between two modules

    Five categories or levels of coupling (non-linear scale)

  • 8/14/2019 se7_ch07_v07

    31/93

    Slide 7.31

    The McGraw-Hill Companies, 2007

    7.3.1 Content Coupling

    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

  • 8/14/2019 se7_ch07_v07

    32/93

    Slide 7.32

    The McGraw-Hill Companies, 2007

    Why Is Content Coupling So Bad?

    Almost any change to module q, even recompilingq with a new compiler or assembler, requires achange to module p

  • 8/14/2019 se7_ch07_v07

    33/93

    Slide 7.33

    The McGraw-Hill Companies, 2007

    7.3.2 Common Coupling

    Two modules are common coupled if they have

    write access to global data

    Example 1Modulesccaandccbcan access and change the

    value ofglobal_variable

    Figure 7.9

    3 2 C C ( )

  • 8/14/2019 se7_ch07_v07

    34/93

    Slide 7.34

    The McGraw-Hill Companies, 2007

    7.3.2 Common Coupling (contd)

    Example 2:

    Modulesccaandccbboth have access to the same

    database, and can both read andwrite the same record

    Example 3:FORTRANcommon

    COBOLcommon (nonstandard)

    COBOL-80global

    Wh I C C li S B d?

  • 8/14/2019 se7_ch07_v07

    35/93

    Slide 7.35

    The McGraw-Hill Companies, 2007

    Why Is Common Coupling So Bad?

    It contradicts the spirit of structured

    programmingThe resulting code is virtually unreadable

    What causes this loop to terminate?

    Figure 7.10

    Wh I C C li S B d? ( td)

  • 8/14/2019 se7_ch07_v07

    36/93

    Slide 7.36

    The McGraw-Hill Companies, 2007

    Why Is Common Coupling So Bad? (contd)

    Modules can have side-effects

    This affects their readabilityExample:edit_this_transaction (record_7)

    The entire module must be read to find out what it does

    A change during maintenance to the declaration ofa global variable in one module necessitatescorresponding changes in other modules

    Common-coupled modules are difficult to reuse

    Wh I C C li S B d? ( td)

  • 8/14/2019 se7_ch07_v07

    37/93

    Slide 7.37

    The McGraw-Hill Companies, 2007

    Why Is Common Coupling So Bad? (contd)

    Common coupling between a modulepand the

    rest of the product can change without changingpin any wayClandestine common coupling

    Example: The Linux kernel

    A module is exposed to more data than necessaryThis can lead to computer crime

    7 3 3 C t l C li

  • 8/14/2019 se7_ch07_v07

    38/93

    Slide 7.38

    The McGraw-Hill Companies, 2007

    7.3.3 Control Coupling

    Two modules are control coupled if one passes

    an element of control to the other

    Example 1:An operation code is passed to a module with logical

    cohesion

    Example 2:

    A control switch passed as an argument

    C t l C li ( td)

  • 8/14/2019 se7_ch07_v07

    39/93

    Slide 7.39

    The McGraw-Hill Companies, 2007

    Control Coupling (contd)

    Modulep calls module q

    Message: I have failed data

    Message: I have failed, so write error message ABC123 control

    Wh I C t l C li S B d?

  • 8/14/2019 se7_ch07_v07

    40/93

    Slide 7.40

    The McGraw-Hill Companies, 2007

    Why Is Control Coupling So Bad?

    The modules are not independent

    Module q (the called module) must know the internalstructure and logic of module p

    This affects reusability

    Associated with modules of logical cohesion

    7 3 4 St C li

  • 8/14/2019 se7_ch07_v07

    41/93

    Slide 7.41

    The McGraw-Hill Companies, 2007

    7.3.4 Stamp Coupling

    Some languages allow only simple variables as

    parameters part_number

    satellite_altitude

    degree_of_multiprogramming

    Many languages also support the passing of datastructures part_record

    satellite_coordinates

    segment_table

    St C li ( td)

  • 8/14/2019 se7_ch07_v07

    42/93

    Slide 7.42

    The McGraw-Hill Companies, 2007

    Stamp Coupling (contd)

    Two modules are stamp coupled if a data structure

    is passed as a parameter, but the called moduleoperates on some but not all of the individual

    components of the data structure

    Wh Is Stamp Co pling So Bad?

  • 8/14/2019 se7_ch07_v07

    43/93

    Slide 7.43

    The McGraw-Hill Companies, 2007

    Why Is Stamp Coupling So Bad?

    It is not clear, without reading the entire module,

    which fields of a record are accessed or changedExample

    calculate_withholding (employee_record)

    Difficult to understand

    Unlikely to be reusable

    More data than necessary is passed

    Uncontrolled data access can lead to computer crime

    Why Is Stamp Coupling So Bad? (contd)

  • 8/14/2019 se7_ch07_v07

    44/93

    Slide 7.44

    The McGraw-Hill Companies, 2007

    Why Is Stamp Coupling So Bad? (contd)

    However, there is nothing wrong with passing a

    data structure as a parameter, provided that allthecomponents of the data structure are accessed

    and/or changed

    Examples:invert_matrix (original_matrix, inverted_matrix);

    print_inventory_record (warehouse_record);

  • 8/14/2019 se7_ch07_v07

    45/93

    Why Is Data Coupling So Good?

  • 8/14/2019 se7_ch07_v07

    46/93

    Slide 7.46

    The McGraw-Hill Companies, 2007

    Why Is Data Coupling So Good?

    The difficulties of content, common, control, and

    stamp coupling are not present

    Maintenance is easier

  • 8/14/2019 se7_ch07_v07

    47/93

    Coupling Example (contd)

  • 8/14/2019 se7_ch07_v07

    48/93

    Slide 7.48

    The McGraw-Hill Companies, 2007

    Coupling Example (contd)

    Interface description

    Figure 7.12

    Coupling Example (contd)

  • 8/14/2019 se7_ch07_v07

    49/93

    Slide 7.49

    The McGraw-Hill Companies, 2007

    Coupling Example (contd)

    Coupling between all pairs of modules

    Figure 7.13

    7 3 7 The Importance of Coupling

  • 8/14/2019 se7_ch07_v07

    50/93

    Slide 7.50

    The McGraw-Hill Companies, 2007

    7.3.7 The Importance of Coupling

    As a result of tight coupling

    A change to modulepcan require a correspondingchange to moduleq

    If the corresponding change is not made, this leads to

    faults

    Good design has high cohesion and low coupling

    What else characterizes good design? (see over)

    Key Definitions

  • 8/14/2019 se7_ch07_v07

    51/93

    Slide 7.51

    The McGraw-Hill Companies, 2007

    Key Definitions

    Figure 7.14

    7 4 Data Encapsulation

  • 8/14/2019 se7_ch07_v07

    52/93

    Slide 7.52

    The McGraw-Hill Companies, 2007

    7.4 Data Encapsulation

    Example

    Design an operating system for a large mainframecomputer. Batch jobs submitted to the computer will be

    classified as high priority, medium priority, or low

    priority. There must be three queues for incoming batch

    jobs, one for each job type. When a job is submitted bya user, the job is added to the appropriate queue, and

    when the operating system decides that a job is ready

    to be run, it is removed from its queue and memory is

    allocated to it

    Design 1 (Next slide)

    Low cohesion operations on job queues are spread

    all over the product

    Data Encapsulation Design 1

  • 8/14/2019 se7_ch07_v07

    53/93

    Slide 7.53

    The McGraw-Hill Companies, 2007

    Data Encapsulation Design 1

    Figure 7.15

    Data Encapsulation Design 2

  • 8/14/2019 se7_ch07_v07

    54/93

    Slide 7.54

    The McGraw-Hill Companies, 2007

    Data Encapsulation Design 2

    Figure 7.16

    Data Encapsulation (contd)

  • 8/14/2019 se7_ch07_v07

    55/93

    Slide 7.55

    The McGraw-Hill Companies, 2007

    Data Encapsulation (contd)

    m_encapsulation has informational cohesion

    m_encapsulation is an implementation of data

    encapsulation

    A data structure (job_queue) together with operations

    performed on that data structure

    Advantages

    DevelopmentMaintenance

    Data Encapsulation and Development

  • 8/14/2019 se7_ch07_v07

    56/93

    Slide 7.56

    The McGraw-Hill Companies, 2007

    Data Encapsulation and Development

    Data encapsulation is an example ofabstraction

    Job queue example:

    Data structure job_queue

    Three new functions initialize_job_queue

    add_job_to_queue

    delete_job_from_queue

    7 4 1 Data Encapsulation and Development

  • 8/14/2019 se7_ch07_v07

    57/93

    Slide 7.57

    The McGraw-Hill Companies, 2007

    7.4.1 Data Encapsulation and Development

    Abstraction

    Conceptualize problem at a higher level Job queues and operations on job queues

    Not a lower level Records or arrays

    Stepwise Refinement

  • 8/14/2019 se7_ch07_v07

    58/93

    Slide 7.58

    The McGraw-Hill Companies, 2007

    Stepwise Refinement

    1. Design the product in terms of higher level

    conceptsIt is irrelevant how job queues are implemented

    2. Then design the lower level componentsTotally ignore what use will be made of them

    Stepwise Refinement (contd)

  • 8/14/2019 se7_ch07_v07

    59/93

    Slide 7.59

    The McGraw-Hill Companies, 2007

    Stepwise Refinement (contd)

    In the 1st step, assume the existence of the lower

    level

    Our concern is the behavior of the data structure job_queue

    In the 2nd step, ignore the existence of the higher

    level

    Our concern is the implementation of that behavior

    In a larger product, there will be many levels of

    abstraction

    7 4 2 Data Encapsulation and Maintenance

  • 8/14/2019 se7_ch07_v07

    60/93

    Slide 7.60

    The McGraw-Hill Companies, 2007

    7.4.2 Data Encapsulation and Maintenance

    Identify the aspects of the product that are likely to

    change

    Design the product so as to minimize the effects of

    changeData structures are unlikely to change

    Implementation details may change

    Data encapsulation provides a way to cope with

    change

    Implementation of JobQueueClass

  • 8/14/2019 se7_ch07_v07

    61/93

    Slide 7.61

    The McGraw-Hill Companies, 2007

    Implementation ofJobQueueClass

    C++

    JavaFigure 7.17 Figure 7.18

    Implementation of queueHandler

  • 8/14/2019 se7_ch07_v07

    62/93

    Slide 7.62

    The McGraw-Hill Companies, 2007

    Implementation ofqueueHandler

    C++ Java

    Figure 7.19 Figure 7.20

    Data Encapsulation and Maintenance (contd)

  • 8/14/2019 se7_ch07_v07

    63/93

    Slide 7.63

    The McGraw-Hill Companies, 2007

    Data Encapsulation and Maintenance (contd)

    What happens if the queue is now implemented

    as a two-way linked list ofJobRecordClass?A module that usesJobRecordClassneed not be

    changed at all, merely recompiled

    Figure 7.22

    Figure 7.21

    C++

    Java

  • 8/14/2019 se7_ch07_v07

    64/93

    7.5 Abstract Data Types

  • 8/14/2019 se7_ch07_v07

    65/93

    Slide 7.65

    The McGraw-Hill Companies, 2007

    7.5 Abstract Data Types

    The problem with both implementations

    There is only one queue, not three

    We need:

    Data type + operations performed on instantiations ofthat data type

    Abstract data type

    Abstract Data Type Example

  • 8/14/2019 se7_ch07_v07

    66/93

    Slide 7.66

    The McGraw-Hill Companies, 2007

    Abstract Data Type Example

    (Problems caused by public attributes solved later)

    Figure 7.24

  • 8/14/2019 se7_ch07_v07

    67/93

  • 8/14/2019 se7_ch07_v07

    68/93

    Slid 7 69Information Hiding (contd)

  • 8/14/2019 se7_ch07_v07

    69/93

    Slide 7.69

    The McGraw-Hill Companies, 2007

    g ( )

    C++ abstract

    data typeimplementation

    with information

    hiding

    Figure 7.26

    Slid 7 70Information Hiding (contd)

  • 8/14/2019 se7_ch07_v07

    70/93

    Slide 7.70

    The McGraw-Hill Companies, 2007

    g ( )

    Effect of information hiding viaprivateattributes

    Figure 7.27

    Slide 7 71Major Concepts of Chapter 7

  • 8/14/2019 se7_ch07_v07

    71/93

    Slide 7.71

    The McGraw-Hill Companies, 2007

    j p p

    Figure 7.28

    Slide 7 727.7 Objects

  • 8/14/2019 se7_ch07_v07

    72/93

    Slide 7.72

    The McGraw-Hill Companies, 2007

    j

    First refinement

    The product is designed in terms of abstract data types

    Variables (objects) are instantiations of abstract data

    types

    Second refinement

    Class: an abstract data type that supports inheritance

    Objects are instantiations of classes

  • 8/14/2019 se7_ch07_v07

    73/93

    Slide 7 74Inheritance (contd)

  • 8/14/2019 se7_ch07_v07

    74/93

    Slide 7.74

    The McGraw-Hill Companies, 2007

    ( )

    DefineParentClassto be a subclass ofHumanBeingClass

    An instance ofParentClasshas all the attributes of aninstance ofHumanBeingClass, plus attributes of his/herown nameOfOldestChild, numberOfChildren

    An instance ofParentClass inherits all attributes ofHumanBeingClass

    Slide 7 75Inheritance (contd)

  • 8/14/2019 se7_ch07_v07

    75/93

    Slide 7.75

    The McGraw-Hill Companies, 2007

    ( )

    The property of inheritance is an essential feature

    of all object-oriented languagesSuch as Smalltalk, C++, Ada 95, Java

    But not of classical languagesSuch as C, COBOL or FORTRAN

    Slide 7 76Inheritance (contd)

  • 8/14/2019 se7_ch07_v07

    76/93

    Slide 7.76

    The McGraw-Hill Companies, 2007

    ( )

    UML notation

    Inheritance is represented by a large open triangle

    Figure 7.29

    Slide 7 77Java Implementation

  • 8/14/2019 se7_ch07_v07

    77/93

    Slide 7.77

    The McGraw-Hill Companies, 2007

    Figure 7.30

    Slide 7 78Aggregation

  • 8/14/2019 se7_ch07_v07

    78/93

    Slide 7.78

    The McGraw-Hill Companies, 2007

    UML notation for aggregation open diamond

    Figure 7.31

    Slide 7.79Association

  • 8/14/2019 se7_ch07_v07

    79/93

    Slide 7.79

    The McGraw-Hill Companies, 2007

    Figure 7.32

    UML notation for association line

    Optional navigation triangle

    Slide 7.80Equivalence of Data and Action

  • 8/14/2019 se7_ch07_v07

    80/93

    The McGraw-Hill Companies, 2007

    Classical paradigm

    record_1.field_2

    Object-oriented paradigm thisObject.attributeB

    thisObject.methodC ()

  • 8/14/2019 se7_ch07_v07

    81/93

    Slide 7.82Inheritance, Polymorphism and Dynamic Binding (contd)

  • 8/14/2019 se7_ch07_v07

    82/93

    The McGraw-Hill Companies, 2007

    Figure 7.33(b)

    Object-oriented paradigm

    Slide 7.83Inheritance, Polymorphism and Dynamic Binding (contd)

  • 8/14/2019 se7_ch07_v07

    83/93

    The McGraw-Hill Companies, 2007

    Classical code to open a file

    The correct method is explicitly selected

    Figure 7.34(a)

    Slide 7.84Inheritance, Polymorphism and Dynamic Binding (contd)

  • 8/14/2019 se7_ch07_v07

    84/93

    The McGraw-Hill Companies, 2007

    Object-oriented code to open a file

    The correct method is invoked at run-time (dynamically)

    Method open can be applied to objects of different classes Polymorphic

    Figure 7.34(b)

  • 8/14/2019 se7_ch07_v07

    85/93

    Slide 7.86Inheritance, Polymorphism and Dynamic Binding (contd)

  • 8/14/2019 se7_ch07_v07

    86/93

    The McGraw-Hill Companies, 2007

    Polymorphism and dynamic binding

    Can have a negative impact on maintenance The code is hard to understand if there are multiple possibilities

    for a specific method

    Polymorphism and dynamic bindingA strength and a weakness of the object-oriented

    paradigm

    Slide 7.877.9 The Object-Oriented Paradigm

  • 8/14/2019 se7_ch07_v07

    87/93

    The McGraw-Hill Companies, 2007

    Reasons for the success of the object-oriented

    paradigm

    The object-oriented paradigm gives overallequal

    attention to data and operations

    At any one time, data or operations may be favored

    A well-designed object (high cohesion, low coupling)

    models all the aspects of one physical entity

    Implementation details are hidden

    Slide 7.88The Object-Oriented Paradigm (contd)

  • 8/14/2019 se7_ch07_v07

    88/93

    The McGraw-Hill Companies, 2007

    The reason why the structured paradigm worked

    well at firstThe alternative was no paradigm at all

    Slide 7.89The Object-Oriented Paradigm (contd)

  • 8/14/2019 se7_ch07_v07

    89/93

    The McGraw-Hill Companies, 2007

    How do we know that the object-oriented

    paradigm is the best current alternative?

    We dont

    However, most reports are favorable Experimental data (e.g., IBM [1994])

    Survey of programmers (e.g., Johnson [2000])

    Slide 7.90Weaknesses of the Object-Oriented Paradigm

  • 8/14/2019 se7_ch07_v07

    90/93

    The McGraw-Hill Companies, 2007

    Development effort and size can be large

    Ones first object-oriented project can be larger

    than expected

    Even taking the learning curve into accountEspecially if there is a GUI

    However, some classes can frequently be reused

    in the next project

    Especially if there is a GUI

  • 8/14/2019 se7_ch07_v07

    91/93

    Slide 7.92Weaknesses of the Object-Oriented Paradigm (contd)

  • 8/14/2019 se7_ch07_v07

    92/93

    The McGraw-Hill Companies, 2007

    As already explained, the use of polymorphism

    and dynamic binding can lead to problems

    It is easy to write bad code in any language

    It is especially easy to write bad object-oriented code

    Slide 7.93The Object-Oriented Paradigm (contd)

  • 8/14/2019 se7_ch07_v07

    93/93

    Some day, the object-oriented paradigm will

    undoubtedly be replaced by something betterAspect-oriented programming is one possibility

    But there are many other possibilities