SlideShare a Scribd company logo
Software Design
Coupling and Cohesion
Attila Magyar
Microsec Ltd.
2016
Design goals
 Optimization for maintenance
 Cost of change
 Adding new feature
 Fixing or modifying existing feature
 Understandability
 How simple is it?
 Robustness and correctness
 How hard is to break it? (code and execution)
 Easy to change, easy to understand, hard to break
Design “principles”, guidelines, metrics
 SOLID by Michael Feathers and Robert C. Martin
 LoD, Tell don’t Ask, Packaging Principles (CCP, CRP), etc
 4 rules of simple design by Kent Beck
 Responsibility Driven Design by Rebecca Wirfs-Brock
 Test Driven Design (GOOS) by Freeman and Pryce
 The Physics of Software by Carlo Pescio
 Connascence by Meilir Page-Jones
 Cohesion and Coupling by Larry Constantine
 Code Smells
 Domain Driven Design by Eric Evans
Design principles, guidelines, metrics
 SOLID
 4 rules of simple design (DRY)
 Responsibility Driven Design (Roles)
 Test Driven Design (GOOS) (Context independence)
 The Physics of Software (Entanglement, Friction)
 Connascence by Meilir Page-Jones
 Code Smells (FE, Inappr. Intimacy, Message Chain,
Large class, Long Method, Long arg. list)
 Cohesion and Coupling by Larry Constantine
Coupling and Cohesion (1979)
Coupling
A B
Coupling
Reasons of coupling
Duplication
Dependency
Types of Coupling
 Content coupling (high)
 Common coupling (also known as Global coupling)
 External coupling
 Control coupling
 Stamp coupling (Data-structured coupling)
 Data coupling
 Message coupling (low)
 No coupling
class A {
private B b;
[..]
public void m() {
b.setZ(b.getX() + b.getY());
}
}
class B {
private int x, y, z;
int getX() { return x; }
int getY() { return y; }
void setZ(int z) { this.z = z; }
}
class A {
private B b;
[..]
public void m() {
b.doYourJob();
}
}
class B {
private int x, y, z;
void doYourJob() {
z = x + y;
}
}
Benefits of low coupling
 Benefits of low coupling
 Less ripple effect when changing code
 Modules are easier to reuse because they are less
context dependent
 Individual modules are easier to understand
Coupling between test and code
 Any assertion upon implementation details
 Testing through non-public API
 Private method/field access
 Overly constrain the protocols
 Interaction testing does not cause fragility by
itself. Don’t blame Mocks.
Cohesion
Cohesion
Types of cohesion
Coincidental cohesion (worst)
Logical cohesion
Procedural cohesion
Communicational/informational cohesion
Sequential cohesion
Functional cohesion (best)
LCOM1, LCOM2 & LCOM3
 LCOM1 = Number of pairs of methods that do not share attributes
M1
I3I1 I2
M2 M3 M4
class A {
private F1 f1;
private F2 f1;
public void m1() {
[...]
f1.m();
}
public void m2() {
[...]
f2.m();
}
}
class A {
private F1 f1;
private F2 f1;
public void m1() {
[...]
f1.m();
}
public void m2() {
[...]
f2.m();
}
}
Low cohesion
 Unrelated responsibilities/functions imply that the
module will have unrelated reasons to change in the
future
 Replacing parts is difficult
 Higher risk of breaking existing functionality when
changing
Summary
 Low coupling between modules
 High cohesion inside modules
 Things that change together are packaged together (CCP).
 Cohesion = Coupling but with different locality?
Food for thought
 Object Design: Roles, Responsibilities, and Collaborations
 https://www.amazon.com/Object-Design-Roles-Responsibilities-Collaborations/dp/0201379430
 Carlo Pescio — Software Design and the Physics of Software
 https://www.youtube.com/watch?v=WPgYju3KnIY
 Growing Object-Oriented Software, Guided by Tests
 https://www.amazon.com/Growing-Object-Oriented-Software-Guided-Tests/dp/0321503627
 Jim Weirich - Connascence Examined
 https://www.youtube.com/watch?v=HQXVKHoUQxY
 Understanding the Four Rules of Simple Design
 https://leanpub.com/4rulesofsimpledesign
 Practical Object-Oriented Design in Ruby
 https://www.amazon.com/Practical-Object-Oriented-Design-Ruby-Addison-Wesley-ebook/dp/B0096BYG7C
 Smalltalk Best Practice Patterns
 https://www.amazon.com/Smalltalk-Best-Practice-Patterns-Kent/dp/013476904X

More Related Content

What's hot (20)

PPTX
unit 3 Design 1
TharuniDiddekunta
 
PPT
Couplingand cohesion student
saurabh kumar
 
PPT
12 couplingand cohesion-student
randhirlpu
 
DOCX
Unit i software design principles 9
kiruthikamurugesan2628
 
PDF
Solid Principles, for better cohesion and lower coupling
Mohammad Shawahneh
 
PDF
Colloquium Report
Deepak Kumar
 
PPTX
Se 381 - lec 23 - 28 - 12 may16 - modularity - ii - cohesion
babak danyal
 
PPTX
Se 381 - lec 22 - 24 - 12 may15 - modularity - i - coupling
babak danyal
 
PPT
Design concepts and principles
saurabhshertukde
 
PPTX
Software design
Zulqarnaintayyab
 
PPTX
Design process and concepts
Slideshare
 
PPTX
Design Concept software engineering
Darshit Metaliya
 
PDF
Software Designing - Software Engineering
Purvik Rana
 
PPTX
Software design
Naveen Sagayaselvaraj
 
PPTX
Software Design and Modularity
Danyal Ahmad
 
PPTX
Design techniques
Amit Debnath
 
PDF
SE2018_Lec 18_ Design Principles and Design Patterns
Amr E. Mohamed
 
PPT
Unit iii(part d - component level design)
BALAJI A
 
PPT
Component based models and technology
Saransh Garg
 
PPT
Component based models and technology
Mayukh Maitra
 
unit 3 Design 1
TharuniDiddekunta
 
Couplingand cohesion student
saurabh kumar
 
12 couplingand cohesion-student
randhirlpu
 
Unit i software design principles 9
kiruthikamurugesan2628
 
Solid Principles, for better cohesion and lower coupling
Mohammad Shawahneh
 
Colloquium Report
Deepak Kumar
 
Se 381 - lec 23 - 28 - 12 may16 - modularity - ii - cohesion
babak danyal
 
Se 381 - lec 22 - 24 - 12 may15 - modularity - i - coupling
babak danyal
 
Design concepts and principles
saurabhshertukde
 
Software design
Zulqarnaintayyab
 
Design process and concepts
Slideshare
 
Design Concept software engineering
Darshit Metaliya
 
Software Designing - Software Engineering
Purvik Rana
 
Software design
Naveen Sagayaselvaraj
 
Software Design and Modularity
Danyal Ahmad
 
Design techniques
Amit Debnath
 
SE2018_Lec 18_ Design Principles and Design Patterns
Amr E. Mohamed
 
Unit iii(part d - component level design)
BALAJI A
 
Component based models and technology
Saransh Garg
 
Component based models and technology
Mayukh Maitra
 

Viewers also liked (18)

PPTX
Cohesion & Coupling
Jagnesh Chawla
 
PDF
CakeFest 2011 - Coupling and cohesion
Carl Sutton
 
PDF
Chapter 5 software design
Piyush Gogia
 
PPTX
CHAPTER 2
mohd_mizan
 
PDF
Cohesion and coupling metrics for workflow process design
Giorgio Sironi
 
PPTX
DHTML - Events & Buttons
Deep Patel
 
PPTX
Cohesion and coupling
Aprajita (Abbey) Singh
 
PPS
Paisajes de asturias sara
Ofelia Lopez
 
PDF
Orbiti Ex Michael Greth Cms Shoot Out
Michael Greth
 
DOCX
18 ene-2011
El Rincon de la Faceac
 
DOCX
Dss02.51 del 25 del 11 de 1962
Alejandro OssesAlvarado
 
PPT
local_and_mobile_search-gregory_markel.ppt
zachbrowne
 
PPTX
Pascual sem1
Rodrigo Pascual
 
PDF
Information Sojall Desy Clean
Lars Gather
 
PPTX
Food Cargo Theft: Prevention and Response
AudioEducator
 
PPTX
Présentation Agence Tagora
stephchevance
 
PDF
inVision BrandsPortfolio
timtalkstech
 
Cohesion & Coupling
Jagnesh Chawla
 
CakeFest 2011 - Coupling and cohesion
Carl Sutton
 
Chapter 5 software design
Piyush Gogia
 
CHAPTER 2
mohd_mizan
 
Cohesion and coupling metrics for workflow process design
Giorgio Sironi
 
DHTML - Events & Buttons
Deep Patel
 
Cohesion and coupling
Aprajita (Abbey) Singh
 
Paisajes de asturias sara
Ofelia Lopez
 
Orbiti Ex Michael Greth Cms Shoot Out
Michael Greth
 
Dss02.51 del 25 del 11 de 1962
Alejandro OssesAlvarado
 
local_and_mobile_search-gregory_markel.ppt
zachbrowne
 
Pascual sem1
Rodrigo Pascual
 
Information Sojall Desy Clean
Lars Gather
 
Food Cargo Theft: Prevention and Response
AudioEducator
 
Présentation Agence Tagora
stephchevance
 
inVision BrandsPortfolio
timtalkstech
 
Ad

Similar to Software Design 1: Coupling & cohesion (20)

PPTX
Effective Software Design
Darshan Ashpal
 
PPT
Coupling and cohesion
Sutha31
 
PPTX
EFFECTIVE MODULAR DESIGN.pptx
DrTThendralCompSci
 
PDF
Cohesion and coupling software desgin engineering
QUAID E AWAM UNIVERSITY OF ENGINEERING SCIENCE AND TECHONOLOGY NAWABSHAH
 
PPT
Writing Quality Code
indikaMaligaspe
 
PDF
SE UNIT-3.pdf
Dr. Radhey Shyam
 
PPTX
Unit3 Software engineering UPTU
Mohammad Faizan
 
PPTX
SOFTWARE DESIGN_Module_1_Module_2_3.pptx
shahils1301
 
PPTX
SQA - Lecturhvvvvvvvvvvvvvvvvvvvve 07.pptx
HekmatyarZahir
 
PPTX
Software Design And ArchitectureLecture-3.pptx
arbabmehmoodpak
 
PPTX
Lecture 12
Rana Ali
 
PPTX
2.Modular Design.pptx
REALGROUPS
 
PPTX
Software Engineering Unit 3 PPT Software Design
mayanksingh678141
 
PPTX
software-design [[[l[l[[[[[[[[[[[pj.pptx
israahussein737
 
PPTX
Seminar presentation by geethu..Software engineering .pptx
mujeebrahman7926
 
PPT
Coupling coheshion tps
Preeti Mishra
 
PPTX
software engineering
Abinaya B
 
PPTX
Software engineering
Muhammad Yasir
 
PPT
Software Design (Lectu. re 4).ppt
kethupsam
 
PPT
Mvc grasp
babak danyal
 
Effective Software Design
Darshan Ashpal
 
Coupling and cohesion
Sutha31
 
EFFECTIVE MODULAR DESIGN.pptx
DrTThendralCompSci
 
Cohesion and coupling software desgin engineering
QUAID E AWAM UNIVERSITY OF ENGINEERING SCIENCE AND TECHONOLOGY NAWABSHAH
 
Writing Quality Code
indikaMaligaspe
 
SE UNIT-3.pdf
Dr. Radhey Shyam
 
Unit3 Software engineering UPTU
Mohammad Faizan
 
SOFTWARE DESIGN_Module_1_Module_2_3.pptx
shahils1301
 
SQA - Lecturhvvvvvvvvvvvvvvvvvvvve 07.pptx
HekmatyarZahir
 
Software Design And ArchitectureLecture-3.pptx
arbabmehmoodpak
 
Lecture 12
Rana Ali
 
2.Modular Design.pptx
REALGROUPS
 
Software Engineering Unit 3 PPT Software Design
mayanksingh678141
 
software-design [[[l[l[[[[[[[[[[[pj.pptx
israahussein737
 
Seminar presentation by geethu..Software engineering .pptx
mujeebrahman7926
 
Coupling coheshion tps
Preeti Mishra
 
software engineering
Abinaya B
 
Software engineering
Muhammad Yasir
 
Software Design (Lectu. re 4).ppt
kethupsam
 
Mvc grasp
babak danyal
 
Ad

Recently uploaded (20)

PDF
Generic or Specific? Making sensible software design decisions
Bert Jan Schrijver
 
PDF
MiniTool Partition Wizard Free Crack + Full Free Download 2025
bashirkhan333g
 
PDF
SAP Firmaya İade ABAB Kodları - ABAB ile yazılmıl hazır kod örneği
Salih Küçük
 
PDF
Open Chain Q2 Steering Committee Meeting - 2025-06-25
Shane Coughlan
 
PDF
IDM Crack with Internet Download Manager 6.42 Build 43 with Patch Latest 2025
bashirkhan333g
 
PDF
4K Video Downloader Plus Pro Crack for MacOS New Download 2025
bashirkhan333g
 
PPTX
iaas vs paas vs saas :choosing your cloud strategy
CloudlayaTechnology
 
PDF
UITP Summit Meep Pitch may 2025 MaaS Rebooted
campoamor1
 
PPTX
Help for Correlations in IBM SPSS Statistics.pptx
Version 1 Analytics
 
PDF
Download Canva Pro 2025 PC Crack Full Latest Version
bashirkhan333g
 
PPTX
Milwaukee Marketo User Group - Summer Road Trip: Mapping and Personalizing Yo...
bbedford2
 
PDF
AOMEI Partition Assistant Crack 10.8.2 + WinPE Free Downlaod New Version 2025
bashirkhan333g
 
PPTX
Empowering Asian Contributions: The Rise of Regional User Groups in Open Sour...
Shane Coughlan
 
PDF
AI + DevOps = Smart Automation with devseccops.ai.pdf
Devseccops.ai
 
PPTX
Build a Custom Agent for Agentic Testing.pptx
klpathrudu
 
PPTX
Agentic Automation Journey Series Day 2 – Prompt Engineering for UiPath Agents
klpathrudu
 
PDF
TheFutureIsDynamic-BoxLang witch Luis Majano.pdf
Ortus Solutions, Corp
 
PPTX
Customise Your Correlation Table in IBM SPSS Statistics.pptx
Version 1 Analytics
 
PDF
Simplify React app login with asgardeo-sdk
vaibhav289687
 
PPTX
Comprehensive Risk Assessment Module for Smarter Risk Management
EHA Soft Solutions
 
Generic or Specific? Making sensible software design decisions
Bert Jan Schrijver
 
MiniTool Partition Wizard Free Crack + Full Free Download 2025
bashirkhan333g
 
SAP Firmaya İade ABAB Kodları - ABAB ile yazılmıl hazır kod örneği
Salih Küçük
 
Open Chain Q2 Steering Committee Meeting - 2025-06-25
Shane Coughlan
 
IDM Crack with Internet Download Manager 6.42 Build 43 with Patch Latest 2025
bashirkhan333g
 
4K Video Downloader Plus Pro Crack for MacOS New Download 2025
bashirkhan333g
 
iaas vs paas vs saas :choosing your cloud strategy
CloudlayaTechnology
 
UITP Summit Meep Pitch may 2025 MaaS Rebooted
campoamor1
 
Help for Correlations in IBM SPSS Statistics.pptx
Version 1 Analytics
 
Download Canva Pro 2025 PC Crack Full Latest Version
bashirkhan333g
 
Milwaukee Marketo User Group - Summer Road Trip: Mapping and Personalizing Yo...
bbedford2
 
AOMEI Partition Assistant Crack 10.8.2 + WinPE Free Downlaod New Version 2025
bashirkhan333g
 
Empowering Asian Contributions: The Rise of Regional User Groups in Open Sour...
Shane Coughlan
 
AI + DevOps = Smart Automation with devseccops.ai.pdf
Devseccops.ai
 
Build a Custom Agent for Agentic Testing.pptx
klpathrudu
 
Agentic Automation Journey Series Day 2 – Prompt Engineering for UiPath Agents
klpathrudu
 
TheFutureIsDynamic-BoxLang witch Luis Majano.pdf
Ortus Solutions, Corp
 
Customise Your Correlation Table in IBM SPSS Statistics.pptx
Version 1 Analytics
 
Simplify React app login with asgardeo-sdk
vaibhav289687
 
Comprehensive Risk Assessment Module for Smarter Risk Management
EHA Soft Solutions
 

Software Design 1: Coupling & cohesion

  • 1. Software Design Coupling and Cohesion Attila Magyar Microsec Ltd. 2016
  • 2. Design goals  Optimization for maintenance  Cost of change  Adding new feature  Fixing or modifying existing feature  Understandability  How simple is it?  Robustness and correctness  How hard is to break it? (code and execution)  Easy to change, easy to understand, hard to break
  • 3. Design “principles”, guidelines, metrics  SOLID by Michael Feathers and Robert C. Martin  LoD, Tell don’t Ask, Packaging Principles (CCP, CRP), etc  4 rules of simple design by Kent Beck  Responsibility Driven Design by Rebecca Wirfs-Brock  Test Driven Design (GOOS) by Freeman and Pryce  The Physics of Software by Carlo Pescio  Connascence by Meilir Page-Jones  Cohesion and Coupling by Larry Constantine  Code Smells  Domain Driven Design by Eric Evans
  • 4. Design principles, guidelines, metrics  SOLID  4 rules of simple design (DRY)  Responsibility Driven Design (Roles)  Test Driven Design (GOOS) (Context independence)  The Physics of Software (Entanglement, Friction)  Connascence by Meilir Page-Jones  Code Smells (FE, Inappr. Intimacy, Message Chain, Large class, Long Method, Long arg. list)  Cohesion and Coupling by Larry Constantine
  • 9. Types of Coupling  Content coupling (high)  Common coupling (also known as Global coupling)  External coupling  Control coupling  Stamp coupling (Data-structured coupling)  Data coupling  Message coupling (low)  No coupling
  • 10. class A { private B b; [..] public void m() { b.setZ(b.getX() + b.getY()); } } class B { private int x, y, z; int getX() { return x; } int getY() { return y; } void setZ(int z) { this.z = z; } }
  • 11. class A { private B b; [..] public void m() { b.doYourJob(); } } class B { private int x, y, z; void doYourJob() { z = x + y; } }
  • 12. Benefits of low coupling  Benefits of low coupling  Less ripple effect when changing code  Modules are easier to reuse because they are less context dependent  Individual modules are easier to understand
  • 13. Coupling between test and code  Any assertion upon implementation details  Testing through non-public API  Private method/field access  Overly constrain the protocols  Interaction testing does not cause fragility by itself. Don’t blame Mocks.
  • 16. Types of cohesion Coincidental cohesion (worst) Logical cohesion Procedural cohesion Communicational/informational cohesion Sequential cohesion Functional cohesion (best)
  • 17. LCOM1, LCOM2 & LCOM3  LCOM1 = Number of pairs of methods that do not share attributes M1 I3I1 I2 M2 M3 M4
  • 18. class A { private F1 f1; private F2 f1; public void m1() { [...] f1.m(); } public void m2() { [...] f2.m(); } }
  • 19. class A { private F1 f1; private F2 f1; public void m1() { [...] f1.m(); } public void m2() { [...] f2.m(); } }
  • 20. Low cohesion  Unrelated responsibilities/functions imply that the module will have unrelated reasons to change in the future  Replacing parts is difficult  Higher risk of breaking existing functionality when changing
  • 21. Summary  Low coupling between modules  High cohesion inside modules  Things that change together are packaged together (CCP).  Cohesion = Coupling but with different locality?
  • 22. Food for thought  Object Design: Roles, Responsibilities, and Collaborations  https://www.amazon.com/Object-Design-Roles-Responsibilities-Collaborations/dp/0201379430  Carlo Pescio — Software Design and the Physics of Software  https://www.youtube.com/watch?v=WPgYju3KnIY  Growing Object-Oriented Software, Guided by Tests  https://www.amazon.com/Growing-Object-Oriented-Software-Guided-Tests/dp/0321503627  Jim Weirich - Connascence Examined  https://www.youtube.com/watch?v=HQXVKHoUQxY  Understanding the Four Rules of Simple Design  https://leanpub.com/4rulesofsimpledesign  Practical Object-Oriented Design in Ruby  https://www.amazon.com/Practical-Object-Oriented-Design-Ruby-Addison-Wesley-ebook/dp/B0096BYG7C  Smalltalk Best Practice Patterns  https://www.amazon.com/Smalltalk-Best-Practice-Patterns-Kent/dp/013476904X