SlideShare a Scribd company logo
Coupling and Cohesion Pfleeger, S.,  Software Engineering Theory and Practice. Prentice Hall, 2001.
Characteristics of Good Design Component independence High cohesion Low coupling Exception identification and handling Fault prevention and fault tolerance
Coupling: Degree of dependence among components No dependencies Loosely coupled-some dependencies Highly coupled-many dependencies High coupling makes modifying parts of the system difficult, e.g., modifying a component affects all the components to which the component is connected.
Range of Coupling High Coupling Loose Low Content Common Control Stamp Data Uncoupled
Content coupling Definition: One component references contents of another Example: Component directly modifies another’s data Component refers to local data of another component in terms of numerical displacement  Component modifies another’s code, e.g., jumps into the middle of a routine
Example of Content Coupling-1 Part of program handles lookup for customer. When customer not found, component adds customer by directly modifying the contents of the data structure containing customer data.
Example of Content Coupling-2 Part of program handles lookup for customer. When customer not found, component adds customer by directly modifying the contents of the data structure containing customer data. Improvement: When customer not found, component calls the AddCustomer() method that is responsible for maintaining customer data.
Common Coupling  Definition: Two components share data Global data structures Common blocks Usually a poor design choice because Lack of clear responsibility for the data Reduces readability Difficult to determine all the components that affect a data element (reduces maintainability) Difficult to reuse components Reduces ability to control data accesses
Example-1 Each source process writes directly to global data store. Each sink process reads directly from global data store. Process control component maintains current data about state of operation. Gets data from multiple sources. Supplies data to multiple sinks.
Example-2 Each source process writes directly to global data store. Each sink process reads directly from global data store. Improvement Data manager component is responsible for data in data store. Processes send data to and request data from data manager. Process control component maintains current data about state of operation. Gets data from multiple sources. Supplies data to multiple sinks.
Control Coupling Definition: Component passes control parameters to coupled components. May be either good or bad, depending on situation.  Bad when component must be aware of internal structure and logic of another module Good if parameters allow factoring and reuse of functionality
Example Acceptable : Module p calls module q and q passes back flag that says it cannot complete the task, then q is passing data Not Acceptable:  Module p calls module q and q passes back flag that says it cannot complete the task and, as a result, writes a specific message.
Stamp Coupling Definition: Component passes a data structure to another component that does not have access to the entire structure. Requires second component to know how to manipulate the data structure (e.g., needs to know about implementation) May be necessary due to efficiency factors: this is a choice made by insightful designer, not lazy programmer.
Example-1 The print routine of the customer billing accepts a customer data structure as an argument, parses it, and prints the name, address, and billing information. Customer billing system
Example-2 The print routine of the customer billing accepts a customer data structure as an argument, parses it, and prints the name, address, and billing information. Improvement The print routine takes the customer name, address, and billing information as an argument. Customer Billing System
Data Coupling Definition: Two components are data coupled if there are homogeneous data items. Every argument is 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.
Key Idea in Object-Oriented Programming Object-oriented designs tend to have low coupling.
Cohesion Definition: 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 component are directed toward and essential for performing the same task High is good
Range of Cohesion High Cohesion Low Functional Informational Sequential Communicational Procedural Temporal Logical Coincidental
Coincidental Cohesion  Definition: Parts of the component are only related by their location in source code Elements needed to achieve some functionality are scattered throughout the system. Accidental Worst form
Example Print next line Reverse string of characters in second argument Add 7 to 5 th  argument Convert 4 th  argument to float
Logical Cohesion Definition: Elements of component are related logically and not functionally. Several logically related elements are in the same component and one of the elements is selected by the client component.
Example-1 A component reads inputs from tape, disk, and network. All the code for these functions are in the same component.  Operations are related, but the functions are significantly different.
Example-2 A component reads inputs from tape, disk, and network. All the code for these functions are in the same component. Operations are related, but the functions are significantly different. Improvement A device component has a read operation that is overridden by sub-class components. The tape sub-class reads from tape. The disk sub-class reads from disk. The network sub-class reads from the network.
Temporal Cohesion  Definition: Elements of a component are related by timing.  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.
Example-1 A system initialization routine: this routine contains all of the code for initializing all of the parts of the system. Lots of different activities occur, all at init time.
Example-2 A system initialization routine: this routine contains all of the code for initializing all of the parts of the system. Lots of different activities occur, all at init time. Improvement A system initialization routine sends an initialization message to each component. Each component initializes itself at component instantiation time.
Procedural Cohesion Definition: Elements of a component are related only to ensure a particular order of execution. Actions are still weakly connected and unlikely to be reusable
Example ... Read part number from data base update repair record on maintenance file. ... May be useful to abstract the intent of this sequence. Make the data base and repair record components handle reading and updating. Make component that handles more abstract operation.
Communicational Cohesion Definition: Module 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
Example Update record in data base and send it to the printer. database.Update (record). record.Print().
Sequential Cohesion The output of one component is the input to another. Occurs naturally in functional programming languages Good situation
Informational Cohesion Definition: Module 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 single entry and single exit In logical cohesion, actions of module intertwined ADT and object-oriented paradigm promote
Functional Cohesion Definition: Every essential element to a single computation is contained in the component. Every element in the component is essential to the computation. Ideal situation.
Examples of Cohesion-1 Function A Function B Function D Function C Function  E Coincidental Parts unrelated Function A Function A’ Function A’’ logic Logical Similar functions Time t 0 Time t 0  + X Time t 0  + 2X Temporal Related by time Function A Function B Function C Procedural Related by order of functions
Examples of Cohesion-2 Function A part 1 Function A part 2 Function A part 3 Functional Sequential with complete, related functions Function A Function B Function C Communicational Access same data Function A Function B Function C Sequential Output of one is input to another
p q t r s u 1 2 3 4 5 6 No.  In  Out Interface Description p, t, u access the same database in update mode Problem: Define coupling between pairs of modules. 1 Aircraft type Status flag 2 ----- List of aircraft parts 3 Function code ----- 4 ----- List of aircraft parts 5 Part number Part manufacturer 6 Part number Part name
Coupling between pairs of modules q r s t u p q --- --- r --- --- s --- t
Problem: Classify cohesion for each module Compute average daily temperatures at various sites Initialize sums and open files Create new temperature record Store temperature record Close files and print average temperatures Read in site, time, and temperature Store record for specific site Edit site, time, or temperature field
In Class P1: What is the effect of cohesion on maintenance? P2: What is the effect of coupling on maintenance? P3: Produce an example of each type of cohesion. Justify your answers. P4: Produce an example of each type of coupling. Justify your answers.

More Related Content

PPT
Couplingand cohesion student
PDF
CakeFest 2011 - Coupling and cohesion
PPTX
Se 381 - lec 22 - 24 - 12 may15 - modularity - i - coupling
PPTX
Se 381 - lec 23 - 28 - 12 may16 - modularity - ii - cohesion
PDF
software design principles
PDF
Cohesion and Coupling - The Keys To Changing Your Code With Confidence
PPT
Slides chapters 28-32
PPT
Thesis Giani UIC Slides EN
Couplingand cohesion student
CakeFest 2011 - Coupling and cohesion
Se 381 - lec 22 - 24 - 12 may15 - modularity - i - coupling
Se 381 - lec 23 - 28 - 12 may16 - modularity - ii - cohesion
software design principles
Cohesion and Coupling - The Keys To Changing Your Code With Confidence
Slides chapters 28-32
Thesis Giani UIC Slides EN

What's hot (20)

PPT
PPT
Design final
PPTX
Software Design and Modularity
PPS
Software design principles
PPT
Seii unit7 component-level-design
PPT
Design concepts and principles
DOC
Chapter 4 software design
PPT
Pressman ch-11-component-level-design
PPT
Unit iii(part d - component level design)
PPTX
Design Concept software engineering
PPTX
Design process and concepts
PPTX
Design techniques
PDF
Software Designing - Software Engineering
PPTX
Monolithic and Procedural Programming
PPTX
Programming using MPI and OpenMP
PDF
SE UNIT-3.pdf
PPTX
Software design
PPT
5 software design
PPT
Coupling coheshion tps
PPTX
Software architecture
Design final
Software Design and Modularity
Software design principles
Seii unit7 component-level-design
Design concepts and principles
Chapter 4 software design
Pressman ch-11-component-level-design
Unit iii(part d - component level design)
Design Concept software engineering
Design process and concepts
Design techniques
Software Designing - Software Engineering
Monolithic and Procedural Programming
Programming using MPI and OpenMP
SE UNIT-3.pdf
Software design
5 software design
Coupling coheshion tps
Software architecture
Ad

Viewers also liked (20)

PDF
Universal Declarative Services
PPTX
Iterator - a powerful but underappreciated design pattern
KEY
Polymorphism
PPT
C++ Inheritance
PDF
Polymorphism and Software Reuse
PPT
Inheritance in c++ ppt (Powerpoint) | inheritance in c++ ppt presentation | i...
PDF
XKE - Programming Paradigms & Constructs
PDF
Hashing and Hash Tables
PDF
The Data Link Layer
PDF
The Physical Layer
PDF
Classes And Methods
PPTX
Syntax part 6
PPTX
04 design concepts_n_principles
PPTX
Association agggregation and composition
PDF
Data structure and algorithms in c++
PDF
WSO2 Complex Event Processor
PPT
C++: inheritance, composition, polymorphism
PPTX
Cohesion & Coupling
PPT
Cohesion and coherence
PDF
The Network Layer
Universal Declarative Services
Iterator - a powerful but underappreciated design pattern
Polymorphism
C++ Inheritance
Polymorphism and Software Reuse
Inheritance in c++ ppt (Powerpoint) | inheritance in c++ ppt presentation | i...
XKE - Programming Paradigms & Constructs
Hashing and Hash Tables
The Data Link Layer
The Physical Layer
Classes And Methods
Syntax part 6
04 design concepts_n_principles
Association agggregation and composition
Data structure and algorithms in c++
WSO2 Complex Event Processor
C++: inheritance, composition, polymorphism
Cohesion & Coupling
Cohesion and coherence
The Network Layer
Ad

Similar to 12 couplingand cohesion-student (20)

PPT
SE-coupling and cohesion.ppt
PPTX
EFFECTIVE MODULAR DESIGN.pptx
PPTX
Design engineering cohesion by dinesh
PPTX
Cohesion and coupling
PPTX
Seminar presentation by geethu..Software engineering .pptx
PPTX
SOFTWARE DESIGN_Module_1_Module_2_3.pptx
PPTX
software engineering
PPTX
Unit-III(Design).pptx
PPTX
Unit3 Software engineering UPTU
PPTX
Software Engineering Unit 3 PPT Software Design
PPTX
software engineering
PPTX
Cohesion and coupling in software design
PPT
Coupling and cohesion
PPTX
Coupling , Cohesion and there Types
PPTX
SQA - Lecturhvvvvvvvvvvvvvvvvvvvve 07.pptx
PPT
Software Design lovely professional university
DOCX
PDF
Lect17
PPT
5.Software Design.ppt
PPT
"Design Phase: A Deep Dive into Software Design and Development"
SE-coupling and cohesion.ppt
EFFECTIVE MODULAR DESIGN.pptx
Design engineering cohesion by dinesh
Cohesion and coupling
Seminar presentation by geethu..Software engineering .pptx
SOFTWARE DESIGN_Module_1_Module_2_3.pptx
software engineering
Unit-III(Design).pptx
Unit3 Software engineering UPTU
Software Engineering Unit 3 PPT Software Design
software engineering
Cohesion and coupling in software design
Coupling and cohesion
Coupling , Cohesion and there Types
SQA - Lecturhvvvvvvvvvvvvvvvvvvvve 07.pptx
Software Design lovely professional university
Lect17
5.Software Design.ppt
"Design Phase: A Deep Dive into Software Design and Development"

More from randhirlpu (14)

PPT
system software
PPT
16 user interfacedesign
PPT
15 object orienteddesign
PPT
14 functional design
PPT
13 configuration management
PPT
9 project planning
PPT
8 project planning
PPT
7(srs template)
PPT
5(re dfd-erd-data dictionay)
PPTX
Cocomo m odel
system software
16 user interfacedesign
15 object orienteddesign
14 functional design
13 configuration management
9 project planning
8 project planning
7(srs template)
5(re dfd-erd-data dictionay)
Cocomo m odel

Recently uploaded (20)

PDF
Bridging biosciences and deep learning for revolutionary discoveries: a compr...
PDF
Shreyas Phanse Resume: Experienced Backend Engineer | Java • Spring Boot • Ka...
PDF
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
PPTX
20250228 LYD VKU AI Blended-Learning.pptx
PDF
Review of recent advances in non-invasive hemoglobin estimation
PPTX
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
PDF
Mobile App Security Testing_ A Comprehensive Guide.pdf
PDF
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
PDF
Machine learning based COVID-19 study performance prediction
PDF
Encapsulation theory and applications.pdf
PDF
The Rise and Fall of 3GPP – Time for a Sabbatical?
DOCX
The AUB Centre for AI in Media Proposal.docx
PDF
Dropbox Q2 2025 Financial Results & Investor Presentation
PDF
Network Security Unit 5.pdf for BCA BBA.
PDF
cuic standard and advanced reporting.pdf
PPTX
PA Analog/Digital System: The Backbone of Modern Surveillance and Communication
PPTX
Digital-Transformation-Roadmap-for-Companies.pptx
PDF
Per capita expenditure prediction using model stacking based on satellite ima...
PPTX
Big Data Technologies - Introduction.pptx
PDF
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
Bridging biosciences and deep learning for revolutionary discoveries: a compr...
Shreyas Phanse Resume: Experienced Backend Engineer | Java • Spring Boot • Ka...
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
20250228 LYD VKU AI Blended-Learning.pptx
Review of recent advances in non-invasive hemoglobin estimation
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
Mobile App Security Testing_ A Comprehensive Guide.pdf
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
Machine learning based COVID-19 study performance prediction
Encapsulation theory and applications.pdf
The Rise and Fall of 3GPP – Time for a Sabbatical?
The AUB Centre for AI in Media Proposal.docx
Dropbox Q2 2025 Financial Results & Investor Presentation
Network Security Unit 5.pdf for BCA BBA.
cuic standard and advanced reporting.pdf
PA Analog/Digital System: The Backbone of Modern Surveillance and Communication
Digital-Transformation-Roadmap-for-Companies.pptx
Per capita expenditure prediction using model stacking based on satellite ima...
Big Data Technologies - Introduction.pptx
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...

12 couplingand cohesion-student

  • 1. Coupling and Cohesion Pfleeger, S., Software Engineering Theory and Practice. Prentice Hall, 2001.
  • 2. Characteristics of Good Design Component independence High cohesion Low coupling Exception identification and handling Fault prevention and fault tolerance
  • 3. Coupling: Degree of dependence among components No dependencies Loosely coupled-some dependencies Highly coupled-many dependencies High coupling makes modifying parts of the system difficult, e.g., modifying a component affects all the components to which the component is connected.
  • 4. Range of Coupling High Coupling Loose Low Content Common Control Stamp Data Uncoupled
  • 5. Content coupling Definition: One component references contents of another Example: Component directly modifies another’s data Component refers to local data of another component in terms of numerical displacement Component modifies another’s code, e.g., jumps into the middle of a routine
  • 6. Example of Content Coupling-1 Part of program handles lookup for customer. When customer not found, component adds customer by directly modifying the contents of the data structure containing customer data.
  • 7. Example of Content Coupling-2 Part of program handles lookup for customer. When customer not found, component adds customer by directly modifying the contents of the data structure containing customer data. Improvement: When customer not found, component calls the AddCustomer() method that is responsible for maintaining customer data.
  • 8. Common Coupling Definition: Two components share data Global data structures Common blocks Usually a poor design choice because Lack of clear responsibility for the data Reduces readability Difficult to determine all the components that affect a data element (reduces maintainability) Difficult to reuse components Reduces ability to control data accesses
  • 9. Example-1 Each source process writes directly to global data store. Each sink process reads directly from global data store. Process control component maintains current data about state of operation. Gets data from multiple sources. Supplies data to multiple sinks.
  • 10. Example-2 Each source process writes directly to global data store. Each sink process reads directly from global data store. Improvement Data manager component is responsible for data in data store. Processes send data to and request data from data manager. Process control component maintains current data about state of operation. Gets data from multiple sources. Supplies data to multiple sinks.
  • 11. Control Coupling Definition: Component passes control parameters to coupled components. May be either good or bad, depending on situation. Bad when component must be aware of internal structure and logic of another module Good if parameters allow factoring and reuse of functionality
  • 12. Example Acceptable : Module p calls module q and q passes back flag that says it cannot complete the task, then q is passing data Not Acceptable: Module p calls module q and q passes back flag that says it cannot complete the task and, as a result, writes a specific message.
  • 13. Stamp Coupling Definition: Component passes a data structure to another component that does not have access to the entire structure. Requires second component to know how to manipulate the data structure (e.g., needs to know about implementation) May be necessary due to efficiency factors: this is a choice made by insightful designer, not lazy programmer.
  • 14. Example-1 The print routine of the customer billing accepts a customer data structure as an argument, parses it, and prints the name, address, and billing information. Customer billing system
  • 15. Example-2 The print routine of the customer billing accepts a customer data structure as an argument, parses it, and prints the name, address, and billing information. Improvement The print routine takes the customer name, address, and billing information as an argument. Customer Billing System
  • 16. Data Coupling Definition: Two components are data coupled if there are homogeneous data items. Every argument is 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.
  • 17. Key Idea in Object-Oriented Programming Object-oriented designs tend to have low coupling.
  • 18. Cohesion Definition: 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 component are directed toward and essential for performing the same task High is good
  • 19. Range of Cohesion High Cohesion Low Functional Informational Sequential Communicational Procedural Temporal Logical Coincidental
  • 20. Coincidental Cohesion Definition: Parts of the component are only related by their location in source code Elements needed to achieve some functionality are scattered throughout the system. Accidental Worst form
  • 21. Example Print next line Reverse string of characters in second argument Add 7 to 5 th argument Convert 4 th argument to float
  • 22. Logical Cohesion Definition: Elements of component are related logically and not functionally. Several logically related elements are in the same component and one of the elements is selected by the client component.
  • 23. Example-1 A component reads inputs from tape, disk, and network. All the code for these functions are in the same component. Operations are related, but the functions are significantly different.
  • 24. Example-2 A component reads inputs from tape, disk, and network. All the code for these functions are in the same component. Operations are related, but the functions are significantly different. Improvement A device component has a read operation that is overridden by sub-class components. The tape sub-class reads from tape. The disk sub-class reads from disk. The network sub-class reads from the network.
  • 25. Temporal Cohesion Definition: Elements of a component are related by timing. 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.
  • 26. Example-1 A system initialization routine: this routine contains all of the code for initializing all of the parts of the system. Lots of different activities occur, all at init time.
  • 27. Example-2 A system initialization routine: this routine contains all of the code for initializing all of the parts of the system. Lots of different activities occur, all at init time. Improvement A system initialization routine sends an initialization message to each component. Each component initializes itself at component instantiation time.
  • 28. Procedural Cohesion Definition: Elements of a component are related only to ensure a particular order of execution. Actions are still weakly connected and unlikely to be reusable
  • 29. Example ... Read part number from data base update repair record on maintenance file. ... May be useful to abstract the intent of this sequence. Make the data base and repair record components handle reading and updating. Make component that handles more abstract operation.
  • 30. Communicational Cohesion Definition: Module 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
  • 31. Example Update record in data base and send it to the printer. database.Update (record). record.Print().
  • 32. Sequential Cohesion The output of one component is the input to another. Occurs naturally in functional programming languages Good situation
  • 33. Informational Cohesion Definition: Module 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 single entry and single exit In logical cohesion, actions of module intertwined ADT and object-oriented paradigm promote
  • 34. Functional Cohesion Definition: Every essential element to a single computation is contained in the component. Every element in the component is essential to the computation. Ideal situation.
  • 35. Examples of Cohesion-1 Function A Function B Function D Function C Function E Coincidental Parts unrelated Function A Function A’ Function A’’ logic Logical Similar functions Time t 0 Time t 0 + X Time t 0 + 2X Temporal Related by time Function A Function B Function C Procedural Related by order of functions
  • 36. Examples of Cohesion-2 Function A part 1 Function A part 2 Function A part 3 Functional Sequential with complete, related functions Function A Function B Function C Communicational Access same data Function A Function B Function C Sequential Output of one is input to another
  • 37. p q t r s u 1 2 3 4 5 6 No. In Out Interface Description p, t, u access the same database in update mode Problem: Define coupling between pairs of modules. 1 Aircraft type Status flag 2 ----- List of aircraft parts 3 Function code ----- 4 ----- List of aircraft parts 5 Part number Part manufacturer 6 Part number Part name
  • 38. Coupling between pairs of modules q r s t u p q --- --- r --- --- s --- t
  • 39. Problem: Classify cohesion for each module Compute average daily temperatures at various sites Initialize sums and open files Create new temperature record Store temperature record Close files and print average temperatures Read in site, time, and temperature Store record for specific site Edit site, time, or temperature field
  • 40. In Class P1: What is the effect of cohesion on maintenance? P2: What is the effect of coupling on maintenance? P3: Produce an example of each type of cohesion. Justify your answers. P4: Produce an example of each type of coupling. Justify your answers.

Editor's Notes

  • #6: Pp220+ pfleeger
  • #9: Pp220+ pfleeger
  • #12: Example of good: Sort that takes a comparison function as an argument. The sort function is clearly defined: return a list in sorted order, where sorted is determined by a parameter.
  • #13: In right hand side, the sort code is unchanged.
  • #14: Be sure you know the difference between the insightful designer and the lazy programmer. Know what tradeoffs you are making in your design.
  • #22: I don’t even want to think about it.
  • #24: I don’t even want to think about it.
  • #25: I don’t even want to think about it.
  • #27: I don’t even want to think about it.
  • #28: I don’t even want to think about it.
  • #32: I don’t even want to think about it.
  • #41: I don’t even want to think about it.