CS540 Software Design Lecture 3 & 4 1 Lecture 3 & 4: Modularity, Coupling, Cohesion and Abstraction Anita S. Malik Adapted from Schach.

Slides:



Advertisements
Similar presentations
Design Validation CSCI 5801: Software Engineering.
Advertisements

Quality of a Class Abstraction: Coupling & Cohesion Michael L. Collard, Ph.D. Department of Computer Science Kent State University.
Procedural programming in Java
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.
Module: Definition ● A logical collection of related program entities ● Not necessarily a physical concept, e.g., file, function, class, package ● Often.
Slide 7.1 © The McGraw-Hill Companies, 2002 Object-Oriented and Classical Software Engineering Fifth Edition, WCB/McGraw-Hill, 2002 Stephen R. Schach
Jump to first page 1 System Design (Finalizing Design Specifications) Chapter 3d.
Lecture 13: Object- Oriented Concepts Anita S. Malik Adapted from Schach (2004) Chapter 7.
Programming Logic and Design, Introductory, Fourth Edition1 Understanding Computer Components and Operations (continued) A program must be free of syntax.
Programming Logic and Design Fourth Edition, Introductory
OBJECT ORIENTED PROGRAMMING IN C++ LECTURE
The Project AH Computing. Functional Requirements  What the product must do!  Examples attractive welcome screen all options available as clickable.
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,
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.
SE: CHAPTER 7 Writing The Program
Selection Control Structures. Simple Program Design, Fourth Edition Chapter 4 2 Objectives In this chapter you will be able to: Elaborate on the uses.
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.
Slide 7.1 Copyright © 2008 by The McGraw-Hill Companies, Inc. All rights reserved. Object-Oriented Software Engineering WCB/McGraw-Hill, 2008 Stephen R.
Chapter 10 Software Engineering. Understand the software life cycle. Describe the development process models. Understand the concept of modularity in.
CCSB223/SAD/CHAPTER131 Chapter 13 Designing the System Internals.
7.1/108 Introduction To Objects 7.2/108 Modules Cohesion and low Coupling Data encapsulation Abstract data types Information hiding Objects Objects with.
Structured design - 1 © Minder Chen, Produce Paycheck Retrieve Employee Record Global Data Store Offpage Calling Module Called Module System.
Dr D. Greer, Queens University Belfast )Chapter Six 1 Software Engineering Chapter Six Software Design Quality Learning Outcomes.
Software Engineering Issues Software Engineering Concepts System Specifications Procedural Design Object-Oriented Design System Testing.
Systems Design.  Application Design  User Interface Design  Database Design.
Slide 1 Good Methods. Slide 2 Cohesion and Coupling l For structured design These software metrics were used extensively Proven to be effective l For.
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.
SOFTWARE DESIGN & SOFTWARE ENGINEERING Software design is a process in which data, program structure, interface and their details are represented by well.
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.
CS 325: Software Engineering
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.
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.
Software Design Lecture : 8
Software Design Lecture : 10
Object-Oriented and Classical Software Engineering Eighth Edition, WCB/McGraw-Hill, 2011 Stephen R. Schach.
Cohesion and Coupling.
DESIGN CONCEPTS AND PRINCIPLES
Presentation transcript:

CS540 Software Design Lecture 3 & 4 1 Lecture 3 & 4: Modularity, Coupling, Cohesion and Abstraction Anita S. Malik Adapted from Schach (2002) Chapter 7

CS540 Software Design 2Lecture 3 & 4 Modules What is a module? What is a module? A lexically contiguous sequence of program statements, bounded by boundary elements, with an aggregate identifier A lexically contiguous sequence of program statements, bounded by boundary elements, with an aggregate identifier Examples of boundary elements are begin…end pairs or {…} pairs Examples of boundary elements are begin…end pairs or {…} pairs Procedures, functions in classical paradigm are modules. In object-oriented paradigm an object is a module and so is the method within an object Procedures, functions in classical paradigm are modules. In object-oriented paradigm an object is a module and so is the method within an object

CS540 Software Design 3Lecture 3 & 4 Example - Design of Computer Lets consider an example to understand the importance of modularization Lets consider an example to understand the importance of modularization

CS540 Software Design 4Lecture 3 & 4 Design of Computer (contd) A competent architect designs 3 silicon chips as shown in the diagram A competent architect designs 3 silicon chips as shown in the diagram

CS540 Software Design 5Lecture 3 & 4 Design of Computer (contd) 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.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. Resulting “masterpiece”Resulting “masterpiece”

CS540 Software Design 6Lecture 3 & 4 Computer Design (contd) The two designs are functionally equivalent The two designs are functionally equivalent Second design is Second design is Hard to understand Hard to understand Hard to locate faults Hard to locate faults Difficult to extend or enhance Difficult to extend or enhance Cannot be reused in another product Cannot be reused in another product Software Modules must be like the first design Software Modules must be like the first design Maximal relationships within modules and minimal relationships between modules Maximal relationships within modules and minimal relationships between modules

CS540 Software Design 7Lecture 3 & 4 Composite/Structured Design Method for breaking up a product into modules for Method for breaking up a product into modules for Maximal interaction within module, and Maximal interaction within module, and Minimal interaction between modules Minimal interaction between modules Module cohesion Module cohesion Degree of interaction within a module Degree of interaction within a module Module coupling Module coupling Degree of interaction between modules Degree of interaction between modules

CS540 Software Design 8Lecture 3 & 4 Function, Logic, and Context of module In C/SD, the name of a module is its function In C/SD, the name of a module is its function Example Example Module computes square root of double precision integers using Newton’s algorithm. Module is named compute square root Module computes square root of double precision integers using Newton’s algorithm. Module is named compute square root

CS540 Software Design 9Lecture 3 & 4 Cohesion Degree of interaction within a module Degree of interaction within a module Seven categories or levels of cohesion (non-linear scale) Seven categories or levels of cohesion (non-linear scale)

CS540 Software Design 10Lecture 3 & 4 1.Coincidental Cohesion A module has coincidental cohesion if it performs multiple, completely unrelated actions A module has coincidental cohesion if it performs multiple, completely unrelated actions Example Example print next line, reverse string of characters comprising second parameter, add 7 to fifth parameter, convert fourth parameter to floating point print next line, reverse string of characters comprising second parameter, add 7 to fifth parameter, convert fourth parameter to floating point Arise from rules like Arise from rules like “Every module will consist of between 35 and 50 statements” “Every module will consist of between 35 and 50 statements”

CS540 Software Design 11Lecture 3 & 4 Why is Coincidental Cohesion so Bad? Degrades maintainability Degrades maintainability Modules are not reusable Modules are not reusable This is easy to fix This is easy to fix Break into separate modules each performing one task Break into separate modules each performing one task

CS540 Software Design 12Lecture 3 & 4 2.Logical Cohesion A module has logical cohesion when it performs a series of related actions, one of which is selected by the calling module A module has logical cohesion when it performs a series of related actions, one of which is selected by the calling module Example 1 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 Example 2 Module performing all input and output Module performing all input and output Example 3 Example 3 One version of OS/VS2 contained logical cohesion module performing 13 different actions. Interface contained 21 pieces of data One version of OS/VS2 contained logical cohesion module performing 13 different actions. Interface contained 21 pieces of data

CS540 Software Design 13Lecture 3 & 4 Why is Logical Cohesion so Bad? The interface is difficult to understand The interface is difficult to understand Code for more than one action may be intertwined Code for more than one action may be intertwined Difficult to reuse Difficult to reuse

CS540 Software Design 14Lecture 3 & 4 Why is Logical Cohesion so Bad? (contd) A new tape unit is installed A new tape unit is installed What is the effect on the laser printer? What is the effect on the laser printer?

CS540 Software Design 15Lecture 3 & 4 3.Temporal Cohesion A module has temporal cohesion when it performs a series of actions related in time A module has temporal cohesion when it performs a series of actions related in time Example Example open old master file, new master file, transaction file, print file, initialize sales district table, read first transaction record, read first old master record (a.k.a. perform initialization) open old master file, new master file, transaction file, print file, initialize sales district table, read first transaction record, read first old master record (a.k.a. perform initialization)

CS540 Software Design 16Lecture 3 & 4 Why is Temporal Cohesion so Bad? Actions of this module are weakly related to one another, but strongly related to actions in other modules. Actions of this module are weakly related to one another, but strongly related to actions in other modules. Consider sales district table Consider sales district table Not reusable Not reusable

CS540 Software Design 17Lecture 3 & 4 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 A module has procedural cohesion if it performs a series of actions related by the procedure to be followed by the product Example Example read part number and update repair record on master file read part number and update repair record on master file

CS540 Software Design 18Lecture 3 & 4 Why is Procedural Cohesion so Bad? Actions are still weakly connected, so module is not reusable Actions are still weakly connected, so module is not reusable

CS540 Software Design 19Lecture 3 & 4 5.Communicational Cohesion 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 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 Example 1 Example 1 update record in database and write it to audit trail update record in database and write it to audit trail Example 2 Example 2 calculate new coordinates and send them to terminal calculate new coordinates and send them to terminal

CS540 Software Design 20Lecture 3 & 4 Why is Communicational Cohesion so Bad? Still lack of reusability Still lack of reusability

CS540 Software Design 21Lecture 3 & 4 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 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

CS540 Software Design 22Lecture 3 & 4 Why is Informational Cohesion so Good? Essentially, this is an abstract data type Essentially, this is an abstract data type

CS540 Software Design 23Lecture 3 & 4 7.Functional Cohesion Module with functional cohesion performs exactly one action Module with functional cohesion performs exactly one action Example 1 Example 1 get temperature of furnace get temperature of furnace Example 2 Example 2 compute orbital of electron compute orbital of electron Example 3 Example 3 write to floppy disk write to floppy disk Example 4 Example 4 calculate sales commission calculate sales commission

CS540 Software Design 24Lecture 3 & 4 Why is Functional Cohesion so Good? More reusable More reusable Corrective maintenance easier Corrective maintenance easier Fault isolation Fault isolation Fewer regression faults Fewer regression faults Easier to extend product Easier to extend product

CS540 Software Design 25Lecture 3 & 4 Cohesion Case Study

CS540 Software Design 26Lecture 3 & 4 Coupling Degree of interaction between two modules Degree of interaction between two modules Five categories or levels of coupling (non-linear scale) Five categories or levels of coupling (non-linear scale)

CS540 Software Design 27Lecture 3 & 4 1.Content Coupling Two modules are content coupled if one directly references contents of the other Two modules are content coupled if one directly references contents of the other Example 1 Example 1 Module a modifies statement of module b Module a modifies statement of module b Example 2 Example 2 Module a refers to local data of module b in terms of some numerical displacement within b Module a refers to local data of module b in terms of some numerical displacement within b Example 3 Example 3 Module a branches into local label of module b Module a branches into local label of module b

CS540 Software Design 28Lecture 3 & 4 Why is Content Coupling so Bad? Almost any change to b, even recompiling b with new compiler or assembler, requires change to a Almost any change to b, even recompiling b with new compiler or assembler, requires change to a Warning Warning Content coupling can be implemented in Ada through use of overlays implemented via address clauses Content coupling can be implemented in Ada through use of overlays implemented via address clauses

CS540 Software Design 29Lecture 3 & 4 2.Common Coupling Two modules are common coupled if they have write access to global data Two modules are common coupled if they have write access to global data Example 1 Example 1 Modules cca and ccb can access and change value of global variable Modules cca and ccb can access and change value of global variable

CS540 Software Design 30Lecture 3 & 4 2.Common Coupling (contd) Example 2 Example 2 Modules cca and ccb both have access to same database, and can both read and write same record Modules cca and ccb both have access to same database, and can both read and write same record Example 3 Example 3 FORTRAN common FORTRAN common COBOL common (nonstandard) COBOL common (nonstandard) COBOL-80 global COBOL-80 global

CS540 Software Design 31Lecture 3 & 4 Why is Common Coupling so Bad? Contradicts the spirit of structured programming Contradicts the spirit of structured programming The resulting code is virtually unreadable The resulting code is virtually unreadable

CS540 Software Design 32Lecture 3 & 4 Why is Common Coupling so Bad? (contd) Modules can have side-effects Modules can have side-effects This affects their readability This affects their readability Entire module must be read to find out what it does Entire module must be read to find out what it does Difficult to reuse Difficult to reuse Module exposed to more data than necessary Module exposed to more data than necessary

CS540 Software Design 33Lecture 3 & 4 3.Control Coupling Two modules are control coupled if one passes an element of control to the other Two modules are control coupled if one passes an element of control to the other Example 1 Example 1 Operation code passed to module with logical cohesion Operation code passed to module with logical cohesion Example 2 Example 2 Control-switch passed as argument Control-switch passed as argument

CS540 Software Design 34Lecture 3 & 4 Why is Control Coupling so Bad? Modules are not independent; module b (the called module) must know internal structure and logic of module a. Modules are not independent; module b (the called module) must know internal structure and logic of module a. Affects reusability Affects reusability Associated with modules of logical cohesion Associated with modules of logical cohesion

CS540 Software Design 35Lecture 3 & 4 4.Stamp Coupling Some languages allow only simple variables as parameters Some languages allow only simple variables as parameters part number part number satellite altitude satellite altitude degree of multiprogramming degree of multiprogramming Many languages also support passing of data structures Many languages also support passing of data structures part record part record satellite coordinates satellite coordinates segment table segment table

CS540 Software Design 36Lecture 3 & 4 4.Stamp Coupling (contd) 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 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

CS540 Software Design 37Lecture 3 & 4 Why is Stamp Coupling so Bad? It is not clear, without reading the entire module, which fields of a record are accessed or changed It is not clear, without reading the entire module, which fields of a record are accessed or changed Example Example calculate withholding (employee record) Difficult to understand Difficult to understand Unlikely to be reusable Unlikely to be reusable More data than necessary is passed More data than necessary is passed Uncontrolled data access can lead to computer crime Uncontrolled data access can lead to computer crime There is nothing wrong with passing a data structure as a parameter, provided all the components of the data structure are accessed and/or changed There is nothing wrong with passing a data structure as a parameter, provided all the components of the data structure are accessed and/or changed invert matrix (original matrix, inverted matrix); print inventory record (warehouse record);

CS540 Software Design 38Lecture 3 & 4 5.Data Coupling 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] 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] Examples Examples display time of arrival (flight number); display time of arrival (flight number); compute product (first number, second number); compute product (first number, second number); get job with highest priority (job queue); get job with highest priority (job queue);

CS540 Software Design 39Lecture 3 & 4 Why is Data Coupling so Good? The difficulties of content, common, control, and stamp coupling are not present The difficulties of content, common, control, and stamp coupling are not present Maintenance is easier Maintenance is easier

CS540 Software Design 40Lecture 3 & 4 Coupling Case Study

CS540 Software Design 41Lecture 3 & 4 Coupling Case Study (contd) Interface description Interface description

CS540 Software Design 42Lecture 3 & 4 Coupling Case Study (contd) Coupling between all pairs of modules Coupling between all pairs of modules

CS540 Software Design 43Lecture 3 & 4 Coupling Case Study (contd) Good design has high cohesion and low coupling Good design has high cohesion and low coupling What else characterizes good design? What else characterizes good design?