Chapter 9: Coupling & Cohesion Omar Meqdadi SE 273 Lecture 9 Department of Computer Science and Software Engineering University of Wisconsin-Platteville.

Slides:



Advertisements
Similar presentations
Quality of a Class Abstraction: Coupling & Cohesion Michael L. Collard, Ph.D. Department of Computer Science Kent State University.
Advertisements

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.
Communication between modules, cohesion and coupling
1 Software Design Introduction  The chapter will address the following questions:  How do you factor a program into manageable program modules that can.
Slide 7A.1 © The McGraw-Hill Companies, 2005 Object-Oriented and Classical Software Engineering Sixth Edition, WCB/McGraw-Hill, 2005 Stephen R. Schach.
Lecture 9 Improving Software Design CSC301-Winter 2011 – University of Toronto – Department of Computer Science Hesam C. Esfahani
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.
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)
Design The goal is to design a modular solution, using the techniques of: Decomposition Abstraction Encapsulation In Object Oriented Programming this is.
Criteria for good design. aim to appreciate the proper and improper uses of inheritance and appreciate the concepts of coupling and cohesion.
CS 201 Functions Debzani Deb.
Guide To UNIX Using Linux Third Edition
PVK-Ht051 Contents Introduction Requirements Engineering Project Management Software Design Detailed Design and Coding Quality Assurance Maintenance.
Contents Introduction Requirements Engineering Project Management Software Design Detailed Design and Coding Quality Assurance.
Introduction to Software Design Chapter 1. Chapter 1: Introduction to Software Design2 Chapter Objectives To become familiar with the software challenge.
OBJECT ORIENTED PROGRAMMING IN C++ LECTURE
Introduction SWE 619. Why Is Building Good Software Hard? Large software systems enormously complex  Millions of “moving parts” People expect software.
Chapter 9: Coupling & Cohesion Omar Meqdadi SE 273 Lecture 9 Department of Computer Science and Software Engineering University of Wisconsin-Platteville.
INTRODUCTION TO PROGRAMMING STRUCTURE Chapter 4 1.
สาขาวิชาเทคโนโลยี สารสนเทศ คณะเทคโนโลยีสารสนเทศ และการสื่อสาร.
Coupling and Cohesion Pfleeger, S., Software Engineering Theory and Practice. Prentice Hall, 2001.
Coupling and Cohesion Source:
Design (1) Design involves decisions on how to deliver the agreed functionality to the users. Design involves development of a clear, unambiguous and consistent.
Introduction CS 3358 Data Structures. What is Computer Science? Computer Science is the study of algorithms, including their  Formal and mathematical.
SOFTWARE DESIGN (SWD) Instructor: Dr. Hany H. Ammar
Chapter 06 (Part I) Functions and an Introduction to Recursion.
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.
Modularity Lecture 4 Course Name: High Level Programming Language Year : 2010.
SE: CHAPTER 7 Writing The Program
Cohesion and Coupling CS 4311
Introduction CS 3358 Data Structures. What is Computer Science? Computer Science is the study of algorithms, including their  Formal and mathematical.
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.
Coupling Cohesion Chandan R. Rupakheti Steve Chenoweth (Chapter 18)
CPS120: Introduction to Computer Science Lecture 14 Functions.
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.
SOFTWARE DESIGN. INTRODUCTION There are 3 distinct types of activities in design 1.External design 2.Architectural design 3.Detailed design Architectural.
Dr D. Greer, Queens University Belfast )Chapter Six 1 Software Engineering Chapter Six Software Design Quality Learning Outcomes.
Software Engineering and Object-Oriented Design Topics: Solutions Modules Key Programming Issues Development Methods Object-Oriented Principles.
SEG 4110 – Advanced Software Design and Reengineering Topic T Introduction to Refactoring.
Chapter 1 Data Abstraction: The Walls CS Data Structures Mehmet H Gunes Modified from authors’ slides.
Systems Design.  Application Design  User Interface Design  Database Design.
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.
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.
Lecture 12 Implementation Issues with Polymorphism.
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.
Designing classes How to write classes in a way that they are easily understandable, maintainable and reusable 6.0.
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.
7. Modular and structured design
Coupling and Cohesion Rajni Bhalla.
Coupling and Cohesion 1.
Cohesion and Coupling Chapter 5, Pfleeger 01/01/10.
Objects First with Java
Improving the Design “Can the design be better?”
CS223: Software Engineering
Programming Logic and Design Fourth Edition, Comprehensive
Software Design Lecture : 9.
Software Design Lecture : 8
Cohesion and Coupling.
DESIGN CONCEPTS AND PRINCIPLES
Presentation transcript:

Chapter 9: Coupling & Cohesion Omar Meqdadi SE 273 Lecture 9 Department of Computer Science and Software Engineering University of Wisconsin-Platteville

2 Topics covered Modules Cohesion Coupling

Module: definition A logical collection of related program entities Not necessarily a physical concept, e.g., file, function, class, package Often requires multiple program entities to express:  Linked list module may require many class, e.g., list, node, iterators, etc.

Why Use Modules? Simplify testing Increase program understanding Increase reuse Reduce maintenance costs for fixes and enhancements Permit replacement

Desired Interaction Minimize external module interaction  modules can be used independently  easier to test  easier to replace  easier to understand Maximize internal module interaction  easier to understand  easier to test

Characteristics Cohesion – Internal interaction of the module. Crisp abstraction of purpose Coupling – External interaction of the module with other modules Action – Behaviour of the module. What it does Logic – How it performs the behaviour. Algorithm used Context – Specific usage of the module

Cohesion In order from good (high) to bad (low)  Informational  Functional  Communicational  Procedural  Temporal  Logical  Coincidental

Coincidental Cohesion Performs multiple, completely unrelated actions May be based on factors outside of the design, i.e., skillset or interest of developers, avoidance of small modules Problems:  No reusability  Poor correct maintenance and enhancement Solution :  Break into smaller modules

/* Joe's Stuff */ // converts a path in windows to one in linux string win2lin(string); // calculate the number of days since the beginning of time int days(string); // outputs a financial report void outputreport(financedata, std::cout);

Logical Cohesion Module performs a series of related actions, one of which is selected by the calling module Parts of the module are related in a logical way, but not the primary logical association

/* Output Module */ // outputs a financial report void outputreport(financedata); // outputs the current weather void outputweather(weatherdata); // output a number in a nice formatted way void outputint(int);

Logical Cohesion Problems:  May include high and low-level actions in the same module  May include unused parameters for certain uses  Difficult to understand interface (in order to do something you have to wade through a lot of unrelated possible actions)

Temporal Cohesion Modules performs a series of actions that are related by time Often happens in initialization or shutdown Problems:  Degrades to temporal cohesion if time of action changes  Addition of parts to the system may require additions to multiple modules

/* initialization Module */ void init() { // initializes financial report initreport(financedata); // initializes current weather initweather(weatherdata); // initializes master count totalcount = 0; }

Procedural Cohesion Action based on the ordering of steps on different data Related by usage in ordering  Module read part number from an input file and update directory count Problems:  Changes to the ordering of steps or purpose of steps requires changing the module abstraction  Limited situations where this particular sequence can be reused

Communicational Cohesion Action based on the ordering of steps on all the same data Actions are related but still not completely separated  Module update record in database and write it to the audit trail  Module calculate new trajectory and send it to the printer Problems:  Module cannot be reused

Functional Cohesion Module that performs a single action or achieves a single goal Maintenance involves the entire single module Advantages:  Very reusable because the module is completely independent in action of other modules  Can be replaced easily

Information Cohesion Performs a number of actions Each action has its own entry point and independent code All actions are performed on a shared data structure Object-Oriented

Coupling In order from good (low) to bad (high)  Data Coupling  Stamp Coupling  Control Coupling  Common Coupling  Content Coupling

Content Coupling A module directly references the content of another module  Module p modifies a statement of module q  Module p refers to local data of module q (in terms of a numerical displacement)  Module p branches to a local label of module q

Content ● Content coupled modules are inextricably interlinked – Change to module p requires a change to module q (including recompilation) – Reusing module p requires using module q also

Common Coupling Using global variables All modules have read/write access to a global data block  Single module with write access where all other modules have read access is not common coupling Modules exchange data using the global data block (instead of arguments)

Common Coupling  Problems: Have to look at many modules to determine the current state of a variable Side effects require looking at all the code in a function to see if there are any global effects Changes in one module to the declaration requires changes in all other modules Identical list of global variables must be declared for module to be reused Module is exposed to more data than is needed

Control Coupling One module passes an element of control to another module One module explicitly controls the logic of another  Control switch is passed as an argument  Module p passes an argument to module q that directly tells it what control structure path to take

Control Coupling Control coupling?  Module p calls module q and q passes a flag back to p that indicates an error  Module p calls module q and q passes a flag back to p that tells p that it must output the error “I goofed up” Problems:  Modules should pass data and leave control path decisions private to a module  Independent reuse is not possible

Stamp Coupling One module passes more data then needed to another module  void swap(int v[], int i, int j);  double calcsalary(Employee& e); Often involves records (structs) with lots of fields Problems:  Efficiency considerations Entire record is passed, but only a few fields are used

Data Coupling Only required data is passed from one module to another All arguments are homogenous data items  simple data type  complex data type, but all parts are used Advantages  Allows for reuse, maintenance, understanding, etc.