Slide 7.1 Copyright © 2008 by The McGraw-Hill Companies, Inc. All rights reserved. Object-Oriented Software Engineering WCB/McGraw-Hill, 2008 Stephen R.

Slides:



Advertisements
Similar presentations
Agenda Definitions Evolution of Programming Languages and Personal Computers The C Language.
Advertisements

Quality of a Class Abstraction: Coupling & Cohesion Michael L. Collard, Ph.D. Department of Computer Science Kent State University.
Structured Design. 2 Design Quality – Simplicity “There are two ways of constructing a software design: One is to make it so simple that there are obviously.
1 Software Design Introduction  The chapter will address the following questions:  How do you factor a program into manageable program modules that can.
1 SOFTWARE DESIGN QUALITY COHESION and COUPLING (Part II)
Slide 7A.1 © The McGraw-Hill Companies, 2005 Object-Oriented and Classical Software Engineering Sixth Edition, WCB/McGraw-Hill, 2005 Stephen R. Schach.
What is Software Design?  Introduction  Software design consists of two components, modular design and packaging.  Modular design is the decomposition.
Copyright Irwin/McGraw-Hill Software Design Prepared by Kevin C. Dittman for Systems Analysis & Design Methods 4ed by J. L. Whitten & L. D. Bentley.
UHD::CS3320::CHAP61 INTRODUCTION TO OBJECTS Chapter 6.
1 From Modules to Objects Xiaojun Qi. 2 What Is a Module? A lexically contiguous sequence of program statements, bounded by boundary elements, with an.
Slide 6B.1 Copyright © 2004 by The McGraw-Hill Companies, Inc. All rights reserved. An Introduction to Object-Oriented Systems Analysis and Design with.
Module: Definition ● A logical collection of related program entities ● Not necessarily a physical concept, e.g., file, function, class, package ● Often.
1 SOFTWARE DESIGN QUALITY COHESION and COUPLING (Part I)
Slide 7.1 © The McGraw-Hill Companies, 2002 Object-Oriented and Classical Software Engineering Fifth Edition, WCB/McGraw-Hill, 2002 Stephen R. Schach
PowerPoint Presentation for Dennis, Wixom & Tegarden Systems Analysis and Design Copyright 2001 © John Wiley & Sons, Inc. All rights reserved. Slide 1.
Lecture 13: Object- Oriented Concepts Anita S. Malik Adapted from Schach (2004) Chapter 7.
© 2006 Pearson Addison-Wesley. All rights reserved2-1 Chapter 2 Principles of Programming & Software Engineering.
OBJECT ORIENTED PROGRAMMING IN C++ LECTURE
Chapter 9: Coupling & Cohesion Omar Meqdadi SE 273 Lecture 9 Department of Computer Science and Software Engineering University of Wisconsin-Platteville.
Coupling and Cohesion Pfleeger, S., Software Engineering Theory and Practice. Prentice Hall, 2001.
Coupling and Cohesion Source:
CSCI 6231 Software Engineering Chapter 7 From Modules to Objects
Slide 7.1 Copyright © 2011 by The McGraw-Hill Companies, Inc. All rights reserved. Object-Oriented and Classical Software Engineering Eighth Edition, WCB/McGraw-Hill,
DESIGN.
SWE © Solomon Seifu ELABORATION. SWE © Solomon Seifu Lesson 12-3 Cohesion.
SOFTWARE DESIGN (SWD) Instructor: Dr. Hany H. Ammar
SOFTWARE DESIGN Design Concepts Design is a meaningful engineering representation of something that is to be built It can be traced to a customer’s requirements.
Slide 10.1 Copyright © 2011 by The McGraw-Hill Companies, Inc. All rights reserved. Object-Oriented and Classical Software Engineering Eighth Edition,
1 Software Design Overview Reference: Software Engineering, by Ian Sommerville, Ch. 12 & 13.
SE: CHAPTER 7 Writing The Program
Concepts of Software Quality Yonglei Tao 1. Software Quality Attributes  Reliability  correctness, completeness, consistency, robustness  Testability.
Slide 7.1 © The McGraw-Hill Companies, 2007 Object-Oriented and Classical Software Engineering Seventh Edition, WCB/McGraw-Hill, 2007 Stephen R. Schach.
Cohesion and Coupling CS 4311
An Object-Oriented Approach to Programming Logic and Design Fourth Edition Chapter 6 Using Methods.
Programming Logic and Design Using Methods. 2 Objectives Review how to use a simple method with local variables and constants Create a method that requires.
GRASP: Designing Objects with Responsibilities
Slide 20.1 Copyright © 2004 by The McGraw-Hill Companies, Inc. All rights reserved. An Introduction to Object-Oriented Systems Analysis and Design with.
Chapter 10 Software Engineering. Understand the software life cycle. Describe the development process models. Understand the concept of modularity in.
CS540 Software Design Lecture 3 & 4 1 Lecture 3 & 4: Modularity, Coupling, Cohesion and Abstraction Anita S. Malik Adapted from Schach.
7.1/108 Introduction To Objects 7.2/108 Modules Cohesion and low Coupling Data encapsulation Abstract data types Information hiding Objects Objects with.
1 CSCD 326 Data Structures I Software Design. 2 The Software Life Cycle 1. Specification 2. Design 3. Risk Analysis 4. Verification 5. Coding 6. Testing.
Slide 13.1 © The McGraw-Hill Companies, 2002 Object-Oriented and Classical Software Engineering Fifth Edition, WCB/McGraw-Hill, 2002 Stephen R. Schach.
Dr D. Greer, Queens University Belfast )Chapter Six 1 Software Engineering Chapter Six Software Design Quality Learning Outcomes.
PC204 Lecture 5 Programming Methodologies Copyright 2000 by Conrad Huang and the Regents of the University of California. All rights reserved.
Software Engineering Issues Software Engineering Concepts System Specifications Procedural Design Object-Oriented Design System Testing.
ECE450 - Software Engineering II1 ECE450 – Software Engineering II Today: Key Principles of Software Architecture and Design (II) adapted from Dave Penny’s.
Week 6: Software Design HNDIT Software Engineering Software Design Learning Outcomes  Understand the activities involved in the Design process.
Design CS 470 – Software Engineering I Sheldon X. Liang, PH.D.
Chapter 9: Coupling & Cohesion Omar Meqdadi SE 273 Lecture 9 Department of Computer Science and Software Engineering University of Wisconsin-Platteville.
Slide 7B.31 © The McGraw-Hill Companies, 2005 Object-Oriented and Classical Software Engineering Sixth Edition, WCB/McGraw-Hill, 2005 Stephen R. Schach.
Programming Logic and Design Fifth Edition, Comprehensive Chapter 7 Using Methods.
Coupling and Cohesion Schach, S, R. Object-Oriented and Classical Software Engineering. McGraw-Hill, 2002.
Coupling and Cohesion Pfleeger, S., Software Engineering Theory and Practice. Prentice Hall, 2001.
Further Modularization, Cohesion, and Coupling. Simple Program Design, Fourth Edition Chapter 9 2 Objectives In this chapter you will be able to: Further.
Slide 7.1 Copyright © 2008 by The McGraw-Hill Companies, Inc. All rights reserved. Object-Oriented Software Engineering WCB/McGraw-Hill, 2008 Stephen R.
7. Modular and structured design
Coupling and Cohesion Rajni Bhalla.
Coupling and Cohesion 1.
Object-Oriented and Classical Software Engineering Eighth Edition, WCB/McGraw-Hill, 2011 Stephen R. Schach 1.
Cohesion and Coupling Chapter 5, Pfleeger 01/01/10.
Object-Oriented and Classical Software Engineering Sixth Edition, WCB/McGraw-Hill, 2005 Stephen R. Schach
Improving the Design “Can the design be better?”
FROM MODULES TO OBJECTS.
CS223: Software Engineering
Software Design CMSC 345, Version 1/11.
Programming Logic and Design Fourth Edition, Comprehensive
Software Design Lecture : 9.
Object-Oriented and Classical Software Engineering Eighth Edition, WCB/McGraw-Hill, 2011 Stephen R. Schach.
Cohesion and Coupling.
DESIGN CONCEPTS AND PRINCIPLES
Presentation transcript:

Slide 7.1 Copyright © 2008 by The McGraw-Hill Companies, Inc. All rights reserved. Object-Oriented Software Engineering WCB/McGraw-Hill, 2008 Stephen R. Schach

Slide 7.2 Copyright © 2008 by The McGraw-Hill Companies, Inc. All rights reserved. CHAPTER 7 FROM MODULES TO OBJECTS

Slide 7.3 Copyright © 2008 by The McGraw-Hill Companies, Inc. All rights reserved. Overview l What is a module? l Cohesion l Coupling l Data encapsulation l Abstract data types l Information hiding l Objects l Inheritance, polymorphism, and dynamic binding l The object-oriented paradigm

Slide 7.4 Copyright © 2008 by The McGraw-Hill Companies, Inc. All rights reserved. 7.1 What Is a Module? l 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 Copyright © 2008 by The McGraw-Hill Companies, Inc. All rights reserved. Design of Computer l 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 Copyright © 2008 by The McGraw-Hill Companies, Inc. All rights reserved. Design of Computer (contd) l The architect designs three silicon chips Figure 7.2

Slide 7.7 Copyright © 2008 by The McGraw-Hill Companies, Inc. All rights reserved. Design of Computer (contd) l Redesign with one gate type per chip l Resulting “masterpiece” Figure 7.3

Slide 7.8 Copyright © 2008 by The McGraw-Hill Companies, Inc. All rights reserved. Computer Design (contd) l 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 l Modules must be like the first design – Maximal relationships within modules, and – Minimal relationships between modules

Slide 7.9 Copyright © 2008 by The McGraw-Hill Companies, Inc. All rights reserved. Composite/Structured Design A method for breaking up a product into modules to achieve – Maximal interaction within a module, and – Minimal interaction between modules l Module cohesion – Degree of interaction within a module l Module coupling – Degree of interaction between modules

Slide 7.10 Copyright © 2008 by The McGraw-Hill Companies, Inc. All rights reserved. Function, Logic, and Context of a Module l In C/SD, the name of a module is its function l Example: – A module computes the square root of double precision integers using Newton’s algorithm. The module is named computeSquareRoot

Slide 7.11 Copyright © 2008 by The McGraw-Hill Companies, Inc. All rights reserved. 7.2 Cohesion l The degree of interaction within a module l Seven categories or levels of cohesion (non-linear scale) Figure 7.4

Slide 7.12 Copyright © 2008 by The McGraw-Hill Companies, Inc. All rights reserved Coincidental Cohesion l A module has coincidental cohesion if it performs multiple, completely unrelated actions l Example: – printTheNextLine, reverseStringOfCharactersComprisingSecondparameter, add7ToFifthParameter, convertFourthParameterTofloatingPoint l Such modules arise from rules like – “Every module will consist of between 35 and 50 statements”

Slide 7.13 Copyright © 2008 by The McGraw-Hill Companies, Inc. All rights reserved. Why Is Coincidental Cohesion So Bad? l It degrades maintainability l A module with coincidental cohesion is not reusable l The problem is easy to fix – Break the module into separate modules, each performing one task

Slide 7.14 Copyright © 2008 by The McGraw-Hill Companies, Inc. All rights reserved Logical Cohesion l A module has logical cohesion when it performs a series of related actions, one of which is selected by the calling module

Slide 7.15 Copyright © 2008 by The McGraw-Hill Companies, Inc. All rights reserved. Logical Cohesion (contd) l Example 1: functionCode = 7; newOperation (functionCode, dummy1, dummy2, dummy3); // dummy1, dummy2, and dummy3 are dummy variables, // not used if functionCode is equal to 7 l Example 2: – An object performing all input and output l Example 3: – One version of OS/VS2 contained a module with logical cohesion performing 13 different actions. The interface contains 21 pieces of data

Slide 7.16 Copyright © 2008 by The McGraw-Hill Companies, Inc. All rights reserved. Why Is Logical Cohesion So Bad? l The interface is difficult to understand l Code for more than one action may be intertwined l Difficult to reuse

Slide 7.17 Copyright © 2008 by The McGraw-Hill Companies, Inc. All rights reserved. Why Is Logical Cohesion So Bad? (contd) l A new tape unit is installed – What is the effect on the laser printer? Figure 7.5

Slide 7.18 Copyright © 2008 by The McGraw-Hill Companies, Inc. All rights reserved Temporal Cohesion l A module has temporal cohesion when it performs a series of actions related in time l Example: – openOldMasterFile, newMasterFile, transactionFile, and printFile; initializeSalesDistrictTable, readFirstTransactionRecord, readFirstOldMasterRecord (a.k.a. performInitialization)

Slide 7.19 Copyright © 2008 by The McGraw-Hill Companies, Inc. All rights reserved. Why Is Temporal Cohesion So Bad? l The actions of this module are weakly related to one another, but strongly related to actions in other modules – Consider salesDistrictTable l Not reusable

Slide 7.20 Copyright © 2008 by The McGraw-Hill Companies, Inc. All rights reserved Procedural Cohesion l A module has procedural cohesion if it performs a series of actions related by the procedure to be followed by the product l Example: – readPartNumberAndUpdateRepairRecordOnMasterFile

Slide 7.21 Copyright © 2008 by The McGraw-Hill Companies, Inc. All rights reserved. Why Is Procedural Cohesion So Bad? l The actions are still weakly connected, so the module is not reusable

Slide 7.22 Copyright © 2008 by The McGraw-Hill Companies, Inc. All rights reserved Communicational Cohesion l A module has communicational cohesion if it performs a series of actions related by the procedure to be followed by the product, but in addition all the actions operate on the same data l Example 1: updateRecordInDatabaseAndWriteItToAuditTrail l Example 2: calculateNewCoordinatesAndSendThemToTerminal

Slide 7.23 Copyright © 2008 by The McGraw-Hill Companies, Inc. All rights reserved. Why Is Communicational Cohesion So Bad? l Still lack of reusability

Slide 7.24 Copyright © 2008 by The McGraw-Hill Companies, Inc. All rights reserved Functional Cohesion l A module with functional cohesion performs exactly one action

Slide 7.25 Copyright © 2008 by The McGraw-Hill Companies, Inc. All rights reserved Functional Cohesion l Example 1: – getTemperatureOfFurnace l Example 2: – computeOrbitalOfElectron l Example 3: – writeToDiskette l Example 4: – calculateSalesCommission

Slide 7.26 Copyright © 2008 by The McGraw-Hill Companies, Inc. All rights reserved. Why Is Functional Cohesion So Good? l More reusable l Corrective maintenance is easier – Fault isolation – Fewer regression faults l Easier to extend a product

Slide 7.27 Copyright © 2008 by The McGraw-Hill Companies, Inc. All rights reserved Informational Cohesion l 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

Slide 7.28 Copyright © 2008 by The McGraw-Hill Companies, Inc. All rights reserved. Why Is Informational Cohesion So Good? l Essentially, this is an abstract data type (see later) Figure 7.6

Slide 7.29 Copyright © 2008 by The McGraw-Hill Companies, Inc. All rights reserved Cohesion Example Figure 7.7

Slide 7.30 Copyright © 2008 by The McGraw-Hill Companies, Inc. All rights reserved. Figure Coupling l The degree of interaction between two modules – Five categories or levels of coupling (non-linear scale)

Slide 7.31 Copyright © 2008 by The McGraw-Hill Companies, Inc. All rights reserved Content Coupling l Two modules are content coupled if one directly references contents of the other l Example 1: – Module p modifies a statement of module q l Example 2: – Module p refers to local data of module q in terms of some numerical displacement within q l Example 3: – Module p branches into a local label of module q

Slide 7.32 Copyright © 2008 by The McGraw-Hill Companies, Inc. All rights reserved. Why Is Content Coupling So Bad? Almost any change to module q, even recompiling q with a new compiler or assembler, requires a change to module p

Slide 7.33 Copyright © 2008 by The McGraw-Hill Companies, Inc. All rights reserved Common Coupling l Two modules are common coupled if they have write access to global data l Example 1 – Modules cca and ccb can access and change the value of globalVariable Figure 7.9

Slide 7.34 Copyright © 2008 by The McGraw-Hill Companies, Inc. All rights reserved Common Coupling (contd) l Example 2: – Modules cca and ccb both have access to the same database, and can both read and write the same record l Example 3: – FORTRAN common – COBOL common (nonstandard) – COBOL-80 global

Slide 7.35 Copyright © 2008 by The McGraw-Hill Companies, Inc. All rights reserved. Why Is Common Coupling So Bad? l It contradicts the spirit of structured programming – The resulting code is virtually unreadable – What causes this loop to terminate? Figure 7.10

Slide 7.36 Copyright © 2008 by The McGraw-Hill Companies, Inc. All rights reserved. Why Is Common Coupling So Bad? (contd) l Modules can have side-effects – This affects their readability – Example: editThisTransaction (record7) – The entire module must be read to find out what it does l A change during maintenance to the declaration of a global variable in one module necessitates corresponding changes in other modules l Common-coupled modules are difficult to reuse

Slide 7.37 Copyright © 2008 by The McGraw-Hill Companies, Inc. All rights reserved. Why Is Common Coupling So Bad? (contd) Common coupling between a module p and the rest of the product can change without changing p in any way – “Clandestine common coupling” – Example: The Linux kernel l A module is exposed to more data than necessary – This can lead to computer crime

Slide 7.38 Copyright © 2008 by The McGraw-Hill Companies, Inc. All rights reserved Control Coupling l Two modules are control coupled if one passes an element of control to the other l Example 1: – An operation code is passed to a module with logical cohesion l Example 2: – A control switch passed as an argument

Slide 7.39 Copyright © 2008 by The McGraw-Hill Companies, Inc. All rights reserved. Control Coupling (contd) Module p calls module q l Message: – I have failed — data l Message: – I have failed, so write error message ABC123 — control

Slide 7.40 Copyright © 2008 by The McGraw-Hill Companies, Inc. All rights reserved. Why Is Control Coupling So Bad? l The modules are not independent – Module q (the called module) must know the internal structure and logic of module p – This affects reusability l Associated with modules of logical cohesion

Slide 7.41 Copyright © 2008 by The McGraw-Hill Companies, Inc. All rights reserved Stamp Coupling l Some languages allow only simple variables as parameters – partNumber – satelliteAltitude – degreeOfMultiprogramming l Many languages also support the passing of data structures – partRecord – satelliteCoordinates – segmentTable

Slide 7.42 Copyright © 2008 by The McGraw-Hill Companies, Inc. All rights reserved. Stamp Coupling (contd) l Two modules are stamp coupled if a data structure is passed as a parameter, but the called module operates on some but not all of the individual components of the data structure

Slide 7.43 Copyright © 2008 by The McGraw-Hill Companies, Inc. All rights reserved. Why Is Stamp Coupling So Bad? l It is not clear, without reading the entire module, which fields of a record are accessed or changed – Example calculateWithholding (employeeRecord) l Difficult to understand l Unlikely to be reusable l More data than necessary is passed – Uncontrolled data access can lead to computer crime

Slide 7.44 Copyright © 2008 by The McGraw-Hill Companies, Inc. All rights reserved. Why Is Stamp Coupling So Bad? (contd) l However, there is nothing wrong with passing a data structure as a parameter, provided that all the components of the data structure are accessed and/or changed l Examples: invertMatrix (originalMatrix, invertedMatrix); printInventoryRecord (warehouseRecord);

Slide 7.45 Copyright © 2008 by The McGraw-Hill Companies, Inc. All rights reserved Data Coupling l Two modules are data coupled if all parameters are homogeneous data items (simple parameters, or data structures all of whose elements are used by called module) l Examples: – displayTimeOfArrival (flightNumber); – computeProduct (firstNumber, secondNumber); – getJobWithHighestPriority (jobQueue);

Slide 7.46 Copyright © 2008 by The McGraw-Hill Companies, Inc. All rights reserved. Why Is Data Coupling So Good? l The difficulties of content, common, control, and stamp coupling are not present l Maintenance is easier

Slide 7.47 Copyright © 2008 by The McGraw-Hill Companies, Inc. All rights reserved Coupling Example Figure 7.11

Slide 7.48 Copyright © 2008 by The McGraw-Hill Companies, Inc. All rights reserved. Coupling Example (contd) l Interface description Figure 7.12

Slide 7.49 Copyright © 2008 by The McGraw-Hill Companies, Inc. All rights reserved. Coupling Example (contd) l Coupling between all pairs of modules Figure 7.13

Slide 7.50 Copyright © 2008 by The McGraw-Hill Companies, Inc. All rights reserved The Importance of Coupling l As a result of tight coupling – A change to module p can require a corresponding change to module q – If the corresponding change is not made, this leads to faults l Good design has high cohesion and low coupling – What else characterizes good design? (see over)