Coupling and Cohesion 1.

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.
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.
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)
Jump to first page 1 System Design (Finalizing Design Specifications) Chapter 3d.
Criteria for good design. aim to appreciate the proper and improper uses of inheritance and appreciate the concepts of coupling and cohesion.
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.
Program Design Simple Program Design Third Edition A Step-by-Step Approach 9.
SOFTWARE DESIGN (SWD) Instructor: Dr. Hany H. Ammar
Chapter 06 (Part I) Functions and an Introduction to Recursion.
1 Software Design Reference: Software Engineering, by Ian Sommerville, Ch. 12 & 13, 5 th edition and Ch. 10, 6 th edition.
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.
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.
Cohesion and Coupling CS 4311
System Implementation
Coupling & Cohesion CMSC 201- Fall '11. Vocabulary Routine- A programming unit that performs a task, such as a function, procedure, method, or main class.
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.
Coupling Cohesion Chandan R. Rupakheti Steve Chenoweth (Chapter 18)
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.
CS540 Software Design Lecture 3 & 4 1 Lecture 3 & 4: Modularity, Coupling, Cohesion and Abstraction Anita S. Malik Adapted from Schach.
CMSC 345 Fall 2000 Design Issues. Modularity and Abstraction Characteristic of all design methods Components have clearly defined inputs and outputs,
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.
Refactoring Agile Development Project. Lecture roadmap Refactoring Some issues to address when coding.
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.
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.
7. Modular and structured design
Coupling and Cohesion Rajni Bhalla.
Data Abstraction: The Walls
Verification and Testing
Principles of Programming and Software Engineering
Software Design Mr. Manoj Kumar Kar.
Coupling and Cohesion By Bonnie Ngu.
Cohesion and Coupling Chapter 5, Pfleeger 01/01/10.
Improving the Design “Can the design be better?”
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
Communication between modules, cohesion and coupling
Design Module view What module should the system and which have to be developed . It determines the module structure of components.
Cohesion and Coupling.
DESIGN CONCEPTS AND PRINCIPLES
Presentation transcript:

Coupling and Cohesion 1

Desired Class/Object Interaction Maximize internal interaction (Cohesion) Easier to understand Easier to test Minimize external interaction (Coupling) Can be used independently Easier to replace

Characteristics of Good Design Component independence High Cohesion Low Coupling

What is Coupling? Coupling is a measure of the independence of components Coupling is related to Cohesion It is an indication of the strength of the inter-connections between the components in a design

Highly Coupled These types of systems have multiple inter-connections with components dependent upon each other Component A Component B Component C Component D

Loosely Coupled Loosely coupled systems are made up of components which are independent or almost independent Component A Component B Component C Component D

Uncoupled Uncoupled components have NO interconnections No dependencies Component A Component B Component C Component D

The range of coupling measures High Coupling Content Coupling Common Coupling Control Coupling Stamp Coupling Loose Coupling Data Coupling Uncoupled Low Coupling

Content Coupling A component directly references (shares) the content of another module Component p modifies a statement of component q Component p refers to local data of component q Content coupled components are inextricably interlinked Changes to component p requires a change to component q (including recompilation) Reusing component p requires using component q also

Common Coupling Using global variable (i.e. global coupling) All components have read/write access to a global data block Components exchange data using the global data block (instead of arguments) A single component with write access where all other components have read access is not Common Coupling

Common Coupling (cont.) Have to look at many components to determine the current state of a variable Side-effects require looking at all of the code in a function to see if there are any global effects Changes in one component to the declaration requires changes in all other components Identical list of global variables must be declared for component to be reused Component is exposed to more data than is needed

Control Coupling A component passes control parameters to coupled components May be good or bad depending upon the situation Bad when the component must be aware of internal structure and logic of another component Good if parameters allow factoring and reuse of functionality

Control Coupling Example Acceptable A sort function that accepts a comparison function as an argument Component p calls component q and q returns a flag indicating an error (if any) occurred Unacceptable Component p calls component q and q returns a string indicating the error (if any) that occurred

Stamp Coupling A component passes a data structure to another component that does not have access to the entire structure Requires a second component to know how to manipulate the data structure (e.g., needs to know about the implementation) May be necessary due to efficiency factors: this is a choice made by insightful designers, not lazy programmer

Stamp Coupling Example Address verification Address verification accepts a Customer data structure as an argument, “parses it” and verifies the address bool VerifyAddress (Customer customer) {…} Better bool VerifyAddress ( String address1, String address2, String city, String state, String zipcode) {…}

Data Coupling Two components are data coupled if there are homogeneous data items Every argument is a simple argument or data structure in which all elements are used Good, if it can be achieved Easy to write contracts for this and modify component independently

Cohesion The degree to which all elements of a component are directed towards a single task and all elements directed towards that task are contained in a single component Internal glue with which component is constructed All elements of a component are directed toward and essential for performing the same task High is good

The range of Cohesion Functional High Cohesion Informational Sequential Communicational Procedural Temporal Logical Coincidental Low Cohesion

Coincidental Cohesion Parts of the component performs multiple, completely unrelated actions May be based on factors outside of the design Skillset or interest of developers Avoidance of small components No reusability Difficult corrective maintenance or enhancement Elements needed to achieve some functionality are scattered throughout the system Example: a “Utilities” class

Logical Cohesion Elements of components are related logically and not functionally Several logically related elements are in the same component and one of the elements is selected by the caller May include both high and low-level actions in the same class May include unused parameters for certain uses Interface is difficult to understand In order to do something you have to wade through a lot of unrelated possible actions Example: grouping all output (print, export) routines

Temporal Cohesion Elements of a component are related by timing – grouped together and used during the same phase of execution Difficult to change because you may have to look at numerous components when a change in a data structure is made Increases chances of regression fault Component unlikely to be reusable Often happens in initialization or shutdown Example: a function which is called after catching an exception which closes an open file, creates an error log and notifies the user

Procedural Cohesion Elements of a component are related only to ensure a particular order of execution – procedures (methods) that are called one after another are kept together Actions are still weakly connected and unlikely to be reusable Changes to the ordering of steps or purpose of steps requires changing the component abstraction Example: a function which checks file permissions and then opens the file

Communicational Cohesion Component performs a series of actions related by a sequence of steps to be followed by the product and all actions are performed on the same data – procedures that access the same data are kept together Action based on the ordering of steps on all the same data Actions are related but still not completely separated Module cannot be reused

Sequential Cohesion Methods are together in a class because the output from one part is the input to another part Occurs naturally in functional programming Example: a function which reads data from a file and processed the data

Informational Cohesion Component performs a number of actions, each with its own entry point, with independent code for each action, all performed on the same data Different from logical cohesion Each piece of code has a single entry and single exit In logical cohesion, actions of module intertwined

Functional Cohesion Every essential element to a single computation is contained in the component Every element in the component is essential to the computation Example: tokenizing a string of XML

?

References Chawla, Jagnesh. “Cohesion & Coupling” Pfleeger, S. “Software Engineering Theory and Practice” Prentice Hall 2001