Академический Документы
Профессиональный Документы
Культура Документы
Object-Oriented and
Classical Software
Engineering
Fifth Edition, WCB/McGraw-Hill, 2002
Stephen R. Schach
srs@vuse.vanderbilt.edu
INTRODUCTION TO
OBJECTS
● What is a module?
● Cohesion
● Coupling
● Data encapsulation product maintenance
● Abstract data types
● Information hiding
● Objects
● Inheritance, polymorphism and dynamic
binding
● Cohesion and coupling of objects
● What is a module?
– A lexically contiguous sequence of program statements,
bounded by boundary elements, with an aggregate
identifier
● 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.
● Architect designs
3 silicon chips
● Redesign
with one gate
type per chip
● Resulting
“masterpiece”
● Degrades maintainability
● Modules are not reusable
● This is easy to fix
– Break into separate modules each performing one task
● Not reusable
● Example 2
– compute orbital of electron
● Example 3
– write to floppy disk
● Example 4
– calculate sales commission
© The McGraw-Hill Companies, 2002
Why is functional cohesion so good? Slide 7.26
● More reusable
● Corrective maintenance easier
– Fault isolation
– Fewer regression faults
● Easier to extend product
● Example 1
– Module a modifies statement of module b
● Example 2
– Module a refers to local data of module b in terms
of some numerical displacement within b
● Example 3
– Module a branches into local label of module b
© The McGraw-Hill Companies, 2002
Why Is Content Coupling So Bad? Slide 7.30
● Example 1
– Modules cca and ccb can access and change value of
global variable
© The McGraw-Hill Companies, 2002
2. Common Coupling (contd) Slide 7.32
● Example 2
– Modules cca and ccb both have access to same database,
and can both read and write same record
● Example 3
– FORTRAN common
– COBOL common (nonstandard)
– COBOL-80 global
● Examples
– display time of arrival (flight number);
– compute product (first number, second number);
– get job with highest priority (job queue);
● Interface description
© The McGraw-Hill Companies, 2002
Coupling Case Study (contd) Slide 7.44
● Example
– Design an operating system for a large mainframe
computer. It has been decided that 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 by a 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 product
●
m_encapsulation has informational cohesion
●
m_encapsulation is an implementation of data
encapsulation
– Data structure (job_queue) together with
operations performed on that data structure
● Advantages
– Development
– Maintenance
C++
Java
© The McGraw-Hill Companies, 2002
Implementation of queueHandler Slide 7.55
C++ Java
– C++
Java
© The McGraw-Hill Companies, 2002
Abstract Data Types Slide 7.57
● Data abstraction
– Designer thinks at level of an ADT
● Procedural abstraction
– Define a procedure—extend the language
● Instances of a more general design
concept, information hiding
– Design the modules in way that items likely to
change are hidden
– Future change is localized
– Changes cannot affect other modules
● C++ abstract
data type
implementation
with information
hiding
● First refinement
– Product is designed in terms of abstract data
types
– Variables (“objects”) are instantiations of
abstract data types
● Second refinement
– Class: abstract data type that supports
inheritance
– Objects are instantiations of classes
● UML notation
– Inheritance is represented by a large open triangle
© The McGraw-Hill Companies, 2002
Java implementation Slide 7.66
● UML Notation
● UML Notation
● Classical paradigm
– record_1.field_2
● Object-oriented paradigm
– thisObject.attributeB
– thisObject.methodC ()
● Classical paradigm
– Must explicitly invoke correct
version
● Object-oriented paradigm
● No such thing!
– Object-oriented cohesion and coupling always reduces
to classical cohesion
● The only feature unique to the object-oriented
paradigm is inheritance
– Cohesion has nothing to do with inheritance
– Two objects with the same functionality have the same
cohesion
– It does not matter if this functionality is inherited or not
– Similarly, so-called object-oriented coupling always
reduces to classical coupling