SlideShare a Scribd company logo
Coupling and Cohesion
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 5th argument
• Convert 4th 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 t0
Time t0 + X
Time t0 + 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
Study
• 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

Similar to SE-coupling and cohesion.ppt

Chapter Three.pptx
Chapter Three.pptxChapter Three.pptx
Chapter Three.pptx
ThedronBerhanu
 
Diksha sda presentation
Diksha sda presentationDiksha sda presentation
Diksha sda presentation
dikshagupta111
 
Module Architecture of React-Redux Applications
Module Architecture of React-Redux ApplicationsModule Architecture of React-Redux Applications
Module Architecture of React-Redux Applications
Andrii Sliusar
 
Coupling coheshion tps
Coupling coheshion tpsCoupling coheshion tps
Coupling coheshion tps
Preeti Mishra
 
Pressman ch-11-component-level-design
Pressman ch-11-component-level-designPressman ch-11-component-level-design
Pressman ch-11-component-level-designOliver Cheng
 
EFFECTIVE MODULAR DESIGN.pptx
EFFECTIVE MODULAR DESIGN.pptxEFFECTIVE MODULAR DESIGN.pptx
EFFECTIVE MODULAR DESIGN.pptx
DrTThendralCompSci
 
architectural design
 architectural design architectural design
architectural design
Preeti Mishra
 
agri-commerce hub project-documentation report.pptx
agri-commerce hub project-documentation report.pptxagri-commerce hub project-documentation report.pptx
agri-commerce hub project-documentation report.pptx
MuhweziAmon4
 
OOSE UNIT-1.pdf
OOSE UNIT-1.pdfOOSE UNIT-1.pdf
OOSE UNIT-1.pdf
KarumuriJayasri
 
Component based development | what, why and how
Component based development | what, why and howComponent based development | what, why and how
Component based development | what, why and how
Rakesh Kumar Jha
 
Unit 1: Introduction to DBMS Unit 1 Complete
Unit 1: Introduction to DBMS Unit 1 CompleteUnit 1: Introduction to DBMS Unit 1 Complete
Unit 1: Introduction to DBMS Unit 1 Complete
Raj vardhan
 
Framework Enabling End-Users to Maintain Web Applications (ICICWS2015)
Framework Enabling End-Users to Maintain Web Applications (ICICWS2015)Framework Enabling End-Users to Maintain Web Applications (ICICWS2015)
Framework Enabling End-Users to Maintain Web Applications (ICICWS2015)
Masayuki Nii
 
CPP19 - Revision
CPP19 - RevisionCPP19 - Revision
CPP19 - Revision
Michael Heron
 
Design concepts and principles
Design concepts and principlesDesign concepts and principles
Design concepts and principlessaurabhshertukde
 
Architecture Design in Software Engineering
Architecture Design in Software EngineeringArchitecture Design in Software Engineering
Architecture Design in Software Engineering
cricket2ime
 
Software Engineering - SOFTWARE DESIGN Process
Software Engineering - SOFTWARE DESIGN ProcessSoftware Engineering - SOFTWARE DESIGN Process
Software Engineering - SOFTWARE DESIGN Process
Dr Anuranjan Misra
 
Software design i (2) (1)
Software design   i (2) (1)Software design   i (2) (1)
Software design i (2) (1)
Shagufta shaheen
 
Architectural patterns part 1
Architectural patterns part 1Architectural patterns part 1
Architectural patterns part 1
assinha
 
Data structures and algorithms Module-1.pdf
Data structures and algorithms Module-1.pdfData structures and algorithms Module-1.pdf
Data structures and algorithms Module-1.pdf
DukeCalvin
 

Similar to SE-coupling and cohesion.ppt (20)

Chapter Three.pptx
Chapter Three.pptxChapter Three.pptx
Chapter Three.pptx
 
Diksha sda presentation
Diksha sda presentationDiksha sda presentation
Diksha sda presentation
 
Module Architecture of React-Redux Applications
Module Architecture of React-Redux ApplicationsModule Architecture of React-Redux Applications
Module Architecture of React-Redux Applications
 
Coupling coheshion tps
Coupling coheshion tpsCoupling coheshion tps
Coupling coheshion tps
 
Pressman ch-11-component-level-design
Pressman ch-11-component-level-designPressman ch-11-component-level-design
Pressman ch-11-component-level-design
 
EFFECTIVE MODULAR DESIGN.pptx
EFFECTIVE MODULAR DESIGN.pptxEFFECTIVE MODULAR DESIGN.pptx
EFFECTIVE MODULAR DESIGN.pptx
 
architectural design
 architectural design architectural design
architectural design
 
agri-commerce hub project-documentation report.pptx
agri-commerce hub project-documentation report.pptxagri-commerce hub project-documentation report.pptx
agri-commerce hub project-documentation report.pptx
 
OOSE UNIT-1.pdf
OOSE UNIT-1.pdfOOSE UNIT-1.pdf
OOSE UNIT-1.pdf
 
Component based development | what, why and how
Component based development | what, why and howComponent based development | what, why and how
Component based development | what, why and how
 
Lect17
Lect17Lect17
Lect17
 
Unit 1: Introduction to DBMS Unit 1 Complete
Unit 1: Introduction to DBMS Unit 1 CompleteUnit 1: Introduction to DBMS Unit 1 Complete
Unit 1: Introduction to DBMS Unit 1 Complete
 
Framework Enabling End-Users to Maintain Web Applications (ICICWS2015)
Framework Enabling End-Users to Maintain Web Applications (ICICWS2015)Framework Enabling End-Users to Maintain Web Applications (ICICWS2015)
Framework Enabling End-Users to Maintain Web Applications (ICICWS2015)
 
CPP19 - Revision
CPP19 - RevisionCPP19 - Revision
CPP19 - Revision
 
Design concepts and principles
Design concepts and principlesDesign concepts and principles
Design concepts and principles
 
Architecture Design in Software Engineering
Architecture Design in Software EngineeringArchitecture Design in Software Engineering
Architecture Design in Software Engineering
 
Software Engineering - SOFTWARE DESIGN Process
Software Engineering - SOFTWARE DESIGN ProcessSoftware Engineering - SOFTWARE DESIGN Process
Software Engineering - SOFTWARE DESIGN Process
 
Software design i (2) (1)
Software design   i (2) (1)Software design   i (2) (1)
Software design i (2) (1)
 
Architectural patterns part 1
Architectural patterns part 1Architectural patterns part 1
Architectural patterns part 1
 
Data structures and algorithms Module-1.pdf
Data structures and algorithms Module-1.pdfData structures and algorithms Module-1.pdf
Data structures and algorithms Module-1.pdf
 

More from vishal choudhary

SE-Lecture1.ppt
SE-Lecture1.pptSE-Lecture1.ppt
SE-Lecture1.ppt
vishal choudhary
 
SE-Testing.ppt
SE-Testing.pptSE-Testing.ppt
SE-Testing.ppt
vishal choudhary
 
SE-CyclomaticComplexityand Testing.ppt
SE-CyclomaticComplexityand Testing.pptSE-CyclomaticComplexityand Testing.ppt
SE-CyclomaticComplexityand Testing.ppt
vishal choudhary
 
SE-Lecture-7.pptx
SE-Lecture-7.pptxSE-Lecture-7.pptx
SE-Lecture-7.pptx
vishal choudhary
 
Se-Lecture-6.ppt
Se-Lecture-6.pptSe-Lecture-6.ppt
Se-Lecture-6.ppt
vishal choudhary
 
SE-Lecture-5.pptx
SE-Lecture-5.pptxSE-Lecture-5.pptx
SE-Lecture-5.pptx
vishal choudhary
 
SE-Lecture-8.pptx
SE-Lecture-8.pptxSE-Lecture-8.pptx
SE-Lecture-8.pptx
vishal choudhary
 
SE-Lecture-2.pptx
SE-Lecture-2.pptxSE-Lecture-2.pptx
SE-Lecture-2.pptx
vishal choudhary
 
SE-software design.ppt
SE-software design.pptSE-software design.ppt
SE-software design.ppt
vishal choudhary
 
SE1.ppt
SE1.pptSE1.ppt
SE-Lecture-4.pptx
SE-Lecture-4.pptxSE-Lecture-4.pptx
SE-Lecture-4.pptx
vishal choudhary
 
SE-Lecture=3.pptx
SE-Lecture=3.pptxSE-Lecture=3.pptx
SE-Lecture=3.pptx
vishal choudhary
 
Multimedia-Lecture-Animation.pptx
Multimedia-Lecture-Animation.pptxMultimedia-Lecture-Animation.pptx
Multimedia-Lecture-Animation.pptx
vishal choudhary
 
MultimediaLecture5.pptx
MultimediaLecture5.pptxMultimediaLecture5.pptx
MultimediaLecture5.pptx
vishal choudhary
 
Multimedia-Lecture-7.pptx
Multimedia-Lecture-7.pptxMultimedia-Lecture-7.pptx
Multimedia-Lecture-7.pptx
vishal choudhary
 
MultiMedia-Lecture-4.pptx
MultiMedia-Lecture-4.pptxMultiMedia-Lecture-4.pptx
MultiMedia-Lecture-4.pptx
vishal choudhary
 
Multimedia-Lecture-6.pptx
Multimedia-Lecture-6.pptxMultimedia-Lecture-6.pptx
Multimedia-Lecture-6.pptx
vishal choudhary
 
Multimedia-Lecture-3.pptx
Multimedia-Lecture-3.pptxMultimedia-Lecture-3.pptx
Multimedia-Lecture-3.pptx
vishal choudhary
 
Multimedia-Lecture-1.pptx
Multimedia-Lecture-1.pptxMultimedia-Lecture-1.pptx
Multimedia-Lecture-1.pptx
vishal choudhary
 

More from vishal choudhary (20)

SE-Lecture1.ppt
SE-Lecture1.pptSE-Lecture1.ppt
SE-Lecture1.ppt
 
SE-Testing.ppt
SE-Testing.pptSE-Testing.ppt
SE-Testing.ppt
 
SE-CyclomaticComplexityand Testing.ppt
SE-CyclomaticComplexityand Testing.pptSE-CyclomaticComplexityand Testing.ppt
SE-CyclomaticComplexityand Testing.ppt
 
SE-Lecture-7.pptx
SE-Lecture-7.pptxSE-Lecture-7.pptx
SE-Lecture-7.pptx
 
Se-Lecture-6.ppt
Se-Lecture-6.pptSe-Lecture-6.ppt
Se-Lecture-6.ppt
 
SE-Lecture-5.pptx
SE-Lecture-5.pptxSE-Lecture-5.pptx
SE-Lecture-5.pptx
 
XML.pptx
XML.pptxXML.pptx
XML.pptx
 
SE-Lecture-8.pptx
SE-Lecture-8.pptxSE-Lecture-8.pptx
SE-Lecture-8.pptx
 
SE-Lecture-2.pptx
SE-Lecture-2.pptxSE-Lecture-2.pptx
SE-Lecture-2.pptx
 
SE-software design.ppt
SE-software design.pptSE-software design.ppt
SE-software design.ppt
 
SE1.ppt
SE1.pptSE1.ppt
SE1.ppt
 
SE-Lecture-4.pptx
SE-Lecture-4.pptxSE-Lecture-4.pptx
SE-Lecture-4.pptx
 
SE-Lecture=3.pptx
SE-Lecture=3.pptxSE-Lecture=3.pptx
SE-Lecture=3.pptx
 
Multimedia-Lecture-Animation.pptx
Multimedia-Lecture-Animation.pptxMultimedia-Lecture-Animation.pptx
Multimedia-Lecture-Animation.pptx
 
MultimediaLecture5.pptx
MultimediaLecture5.pptxMultimediaLecture5.pptx
MultimediaLecture5.pptx
 
Multimedia-Lecture-7.pptx
Multimedia-Lecture-7.pptxMultimedia-Lecture-7.pptx
Multimedia-Lecture-7.pptx
 
MultiMedia-Lecture-4.pptx
MultiMedia-Lecture-4.pptxMultiMedia-Lecture-4.pptx
MultiMedia-Lecture-4.pptx
 
Multimedia-Lecture-6.pptx
Multimedia-Lecture-6.pptxMultimedia-Lecture-6.pptx
Multimedia-Lecture-6.pptx
 
Multimedia-Lecture-3.pptx
Multimedia-Lecture-3.pptxMultimedia-Lecture-3.pptx
Multimedia-Lecture-3.pptx
 
Multimedia-Lecture-1.pptx
Multimedia-Lecture-1.pptxMultimedia-Lecture-1.pptx
Multimedia-Lecture-1.pptx
 

Recently uploaded

Palestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptxPalestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptx
RaedMohamed3
 
Additional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdfAdditional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdf
joachimlavalley1
 
Lapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdfLapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdf
Jean Carlos Nunes Paixão
 
How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17
Celine George
 
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
Nguyen Thanh Tu Collection
 
Thesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.pptThesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.ppt
EverAndrsGuerraGuerr
 
1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx
JosvitaDsouza2
 
Guidance_and_Counselling.pdf B.Ed. 4th Semester
Guidance_and_Counselling.pdf B.Ed. 4th SemesterGuidance_and_Counselling.pdf B.Ed. 4th Semester
Guidance_and_Counselling.pdf B.Ed. 4th Semester
Atul Kumar Singh
 
Honest Reviews of Tim Han LMA Course Program.pptx
Honest Reviews of Tim Han LMA Course Program.pptxHonest Reviews of Tim Han LMA Course Program.pptx
Honest Reviews of Tim Han LMA Course Program.pptx
timhan337
 
Chapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptxChapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptx
Mohd Adib Abd Muin, Senior Lecturer at Universiti Utara Malaysia
 
A Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in EducationA Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in Education
Peter Windle
 
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
siemaillard
 
Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345
beazzy04
 
Supporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptxSupporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptx
Jisc
 
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXXPhrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
MIRIAMSALINAS13
 
Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.
Ashokrao Mane college of Pharmacy Peth-Vadgaon
 
special B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdfspecial B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdf
Special education needs
 
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCECLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
BhavyaRajput3
 
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup   New Member Orientation and Q&A (May 2024).pdfWelcome to TechSoup   New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
TechSoup
 
678020731-Sumas-y-Restas-Para-Colorear.pdf
678020731-Sumas-y-Restas-Para-Colorear.pdf678020731-Sumas-y-Restas-Para-Colorear.pdf
678020731-Sumas-y-Restas-Para-Colorear.pdf
CarlosHernanMontoyab2
 

Recently uploaded (20)

Palestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptxPalestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptx
 
Additional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdfAdditional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdf
 
Lapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdfLapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdf
 
How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17
 
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
 
Thesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.pptThesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.ppt
 
1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx
 
Guidance_and_Counselling.pdf B.Ed. 4th Semester
Guidance_and_Counselling.pdf B.Ed. 4th SemesterGuidance_and_Counselling.pdf B.Ed. 4th Semester
Guidance_and_Counselling.pdf B.Ed. 4th Semester
 
Honest Reviews of Tim Han LMA Course Program.pptx
Honest Reviews of Tim Han LMA Course Program.pptxHonest Reviews of Tim Han LMA Course Program.pptx
Honest Reviews of Tim Han LMA Course Program.pptx
 
Chapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptxChapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptx
 
A Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in EducationA Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in Education
 
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
 
Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345
 
Supporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptxSupporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptx
 
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXXPhrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
 
Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.
 
special B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdfspecial B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdf
 
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCECLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
 
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup   New Member Orientation and Q&A (May 2024).pdfWelcome to TechSoup   New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
 
678020731-Sumas-y-Restas-Para-Colorear.pdf
678020731-Sumas-y-Restas-Para-Colorear.pdf678020731-Sumas-y-Restas-Para-Colorear.pdf
678020731-Sumas-y-Restas-Para-Colorear.pdf
 

SE-coupling and cohesion.ppt

  • 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 5th argument • Convert 4th 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 t0 Time t0 + X Time t0 + 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. Study • 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.