Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
Coupling (computer programming)
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
{{short description|Degree of interdependence between software modules}} In [[software engineering]], '''coupling''' is the degree of interdependence between software [[Modular programming|modules]], a measure of how closely connected two routines or modules are,<ref name="ISO_24765"/> and the strength of the relationships between modules.<ref name="ISOIECTR19759_2005"/> Coupling is not binary but multi-dimensional. <ref name=":0">{{Cite book |last=Hohpe |first=Gregor |title=Enterprise Integration Patterns: Designing, Building, and Deploying Messaging Solutions |publisher=Addison-Wesley Professional |isbn=978-0321200686}}</ref> [[File:CouplingVsCohesion.svg|thumb|Coupling and [[cohesion (computer science)|cohesion]]]] Coupling is usually contrasted with [[cohesion (computer science)|cohesion]]. [[Loose coupling|Low coupling]] often correlates with high cohesion, and vice versa. Low coupling is often thought to be a sign of a well-structured [[computer system]] and a good design, and when combined with high cohesion, supports the general goals of high [[computer programming#Readability of source code|readability]] and [[maintainability]].{{Citation needed|date=October 2013}} ==History== The [[software metric|software quality metrics]] of coupling and cohesion were invented by [[Larry Constantine]] in the late 1960s as part of a [[structured design]], based on characteristics of βgoodβ programming practices that reduced maintenance and modification costs. Structured design, including cohesion and coupling, were published in the article ''Stevens, Myers & Constantine'' (1974)<ref name="Stevens_1974"/> and the book ''Yourdon & Constantine'' (1979),<ref name="Yourdon_1979"/> and the latter subsequently became standard terms. == Types of coupling == {{anchor|Tramp coupling|Pathological coupling|Content coupling|Common-environment coupling|Hybrid coupling|Structural coupling|Temporal coupling|Data type coupling|Hardware coupling}} [[Image:Coupling sketches cropped 1.svg|thumb|300px|right|upright=2.0|Conceptual model of coupling]] Coupling can be "low" (also "[[loose coupling|loose]]" and "weak") or "high" (also "tight" and "strong"). Some types of coupling, in order of highest to lowest coupling, are as follows: === Procedural programming === A module here refers to a subroutine of any kind, i.e. a set of one or more statements having a name and preferably its own set of variable names. ;{{anchor|Content coupling}}Content coupling (high): Content coupling is said to occur when one module uses the code of another module, for instance a branch. This violates [[information hiding]] β a basic software design concept. ;{{anchor|Common coupling}}Common coupling: Common coupling is said to occur when several modules have access to the same global data. But it can lead to uncontrolled error propagation and unforeseen side-effects when changes are made. ;{{anchor|External coupling}}External coupling: External coupling occurs when two modules share an externally imposed data format, communication protocol, or device interface. This is basically related to the communication to external tools and devices. ;{{anchor|Control coupling}}Control coupling: Control coupling is one module controlling the flow of another, by passing it information on what to do (e.g., passing a what-to-do flag). ;{{anchor|Stamp coupling|data-structured coupling}}Stamp coupling (data-structured coupling): Stamp coupling occurs when modules share a composite data structure and use only parts of it, possibly different parts (e.g., passing a whole record to a function that needs only one field of it). :In this situation, a modification in a field that a module does not need may lead to changing the way the module reads the record. To illustrate the concept of stamp coupling, consider a scenario involving a <code>UserProfile</code> [[Software component|component]]. This component is designed to return the entire user profile information in response to [[HTTP|requests]], even when [[User agent|consumers]] only require a specific [[Attribute (computing)|attribute]]. This practice exemplifies stamp coupling, which can lead to significant [[Bandwidth (computing)|bandwidth]] issues, especially at scale. When any attribute within the <code>UserProfile</code> component changes, all consumers that interact with it may need to undergo [[Software testing|testing]], even if they do not utilize the modified attribute. <ref>{{Cite book |last=Richards |first=Mark |title=Fundamentals of Software Architecture: An Engineering Approach |publisher=O'Reilly Media |isbn=978-1492043454}}</ref> ;{{anchor|Data coupling}}Data coupling: Data coupling occurs when modules share data through, for example, parameters. Each datum is an elementary piece, and these are the only data shared (e.g., passing an integer to a function that computes a square root). === Object-oriented programming === ;{{anchor|Subclass coupling}}Subclass coupling: Describes the relationship between a child and its parent. The child is connected to its parent, but the parent is not connected to the child. ;{{anchor|Temporal coupling}}Temporal coupling: It is when two actions are bundled together into one module just because they happen to occur at the same time. In recent work various other coupling concepts have been investigated and used as indicators for different modularization principles used in practice.<ref name="Beck_2011"/> ==== Dynamic coupling ==== <!-- Section title used in redirects --> The goal of defining and measuring this type of coupling is to provide a run-time evaluation of a software system. It has been argued that static coupling metrics lose precision when dealing with an intensive use of dynamic binding or inheritance.<ref name="Arisholm_2004"/> In the attempt to solve this issue, dynamic coupling measures have been taken into account. ==== Semantic coupling ==== <!-- Section title used in redirects --> This kind of a coupling metric considers the conceptual similarities between software entities using, for example, comments and identifiers and relying on techniques such as [[latent semantic indexing]] (LSI). ==== Logical coupling ==== <!-- Section title used in redirects --> {{anchor|evolutionary coupling|Change coupling}}Logical coupling (or evolutionary coupling or change coupling) analysis exploits the release history of a software system to find change patterns among modules or classes: e.g., entities that are likely to be changed together or sequences of changes (a change in a class A is always followed by a change in a class B). == Dimensions of coupling == According to Gregor Hohpe, coupling is multi-dimensional:<ref name=":0" /> * Technology Dependency * Location Dependency * Topology Dependency * Data Format & Type Dependency * Semantic Dependency * Conversation Dependency * Order Dependency * Temporal Dependency == Disadvantages of tight coupling == Tightly coupled systems tend to exhibit the following developmental characteristics, which are often seen as disadvantages: # A change in one module usually forces a [[ripple effect]] of changes in other modules. # Assembly of modules might require more effort and/or time due to the increased inter-module dependency. # A particular module might be harder to [[code reuse|reuse]] and/or test because dependent modules must be included. == Performance issues == Whether loosely or tightly coupled, a system's performance is often reduced by message and parameter creation, transmission, translation (e.g. marshaling) and message interpretation (which might be a reference to a string, array or data structure), which require less overhead than creating a complicated message such as a [[SOAP]] message. Longer messages require more CPU and memory to produce. To optimize runtime performance, message length must be minimized and message meaning must be maximized. ;Message Transmission Overhead and Performance: Since a message must be transmitted in full to retain its complete meaning, message transmission must be optimized. Longer messages require more CPU and memory to transmit and receive. Also, when necessary, receivers must reassemble a message into its original state to completely receive it. Hence, to optimize runtime performance, message length must be minimized and message meaning must be maximized. ;Message Translation Overhead and Performance: Message protocols and messages themselves often contain extra information (i.e., packet, structure, definition and language information). Hence, the receiver often needs to translate a message into a more refined form by removing extra characters and structure information and/or by converting values from one type to another. Any sort of translation increases CPU and/or memory overhead. To optimize runtime performance, message form and content must be reduced and refined to maximize its meaning and reduce translation. ;Message Interpretation Overhead and Performance: All messages must be interpreted by the receiver. Simple messages such as integers might not require additional processing to be interpreted. However, complex messages such as [[SOAP]] messages require a parser and a string transformer for them to exhibit intended meanings. To optimize runtime performance, messages must be refined and reduced to minimize interpretation overhead. == Solutions == One approach to decreasing coupling is [[functional design]], which seeks to limit the responsibilities of modules along functionality. Coupling increases between two classes '''''A''''' and '''''B''''' if: *'''''A''''' has an attribute that refers to (is of type) '''''B'''''. *'''''A''''' calls on services of an object '''''B'''''. *'''''A''''' has a method that references '''''B''''' (via return type or parameter). *'''''A''''' is a subclass of (or implements) class '''''B'''''. Low coupling refers to a relationship in which one module interacts with another module through a simple and stable interface and does not need to be concerned with the other module's internal implementation (see [[Information Hiding]]). Systems such as [[CORBA]] or [[Component Object Model|COM]] allow objects to communicate with each other without having to know anything about the other object's implementation. Both of these systems even allow for objects to communicate with objects written in other languages. == Coupling vs Connascence == Coupling describes the degree and nature of dependency between software components, focusing on what they share (e.g., data, control flow, technology) and how tightly they are bound. It evaluates two key dimensions: strength, which measures how difficult it is to change the dependency, and scope (or visibility), which indicates how widely the dependency is exposed across modules or boundaries. Traditional coupling types typically include content coupling, common coupling, control coupling, stamp coupling, external coupling, and data coupling. <ref name=":03">{{Cite book |title=Practical Guide to Structured Systems Design |isbn=978-0136907695}}</ref><ref name=":12">{{Cite book |title=Designing Data-Intensive Applications: The Big Ideas Behind Reliable, Scalable, and Maintainable Systems |isbn=978-1449373320}}</ref><ref name=":2">{{Cite book |title=Fundamentals of Software Architecture: An Engineering Approach |isbn=978-1492043454}}</ref> [[Connascence]], introduced by Meilir Page-Jones, provides a systematic framework for analyzing and measuring coupling dependencies. It evaluates dependencies based on three dimensions: strength, which measures the effort required to refactor or modify the dependency; locality, which considers how physically or logically close dependent components are in the codebase; and degree, which measures how many components are affected by the dependency. Connascence can be categorized into static (detectable at compile-time) and dynamic (detectable at runtime) forms. Static connascence refers to compile-time dependencies, such as method signatures, while dynamic connascence refers to runtime dependencies, which can manifest in forms like connascence of timing, values, or algorithm. <ref name=":03" /><ref name=":12" /><ref name=":2" /> Each coupling flavor can exhibit multiple types of connascence, a specific type, or, in rare cases, none at all, depending on how the dependency is implemented. Common types of connascence include connascence of name, type, position, and meaning. Certain coupling types naturally align with specific connascence types; for example, data coupling often involves connascence of name or type. However, not every combination of coupling and connascence is practically meaningful. Dependencies relying on parameter order in a method signature demonstrate connascence of position, which is fragile and difficult to refactor because reordering parameters breaks the interface. In contrast, connascence of name, which relies on field or parameter names, is generally more resilient to change. Connascence types themselves exhibit a natural hierarchy of strength, with connascence of name typically considered weaker than connascence of meaning. <ref name=":03" /><ref name=":12" /><ref name=":2" /> Dependencies spanning module boundaries or distributed systems typically have higher coordination costs, increasing the difficulty of refactoring and propagating changes across distant boundaries. Modern practices, such as dependency injection and interface-based programming, are often employed to reduce coupling strength and improve the maintainability of dependencies. <ref name=":03" /><ref name=":12" /><ref name=":2" /> While coupling identifies what is shared between components, connascence evaluates how those dependencies behave, how changes propagate, and how difficult they are to refactor. Strength, locality, and degree are interrelated; dependencies with high strength, wide scope, and spanning distant boundaries are significantly harder to refactor and maintain. Together, coupling provides a high-level overview of dependency relationships, while connascence offers a granular framework for analyzing dependency strength, locality, degree, and resilience to change, supporting the design of maintainable and robust systems. <ref name=":03" /><ref name=":12" /><ref name=":2" /> == Coupling versus cohesion == Coupling and [[cohesion (computer science)|cohesion]] are terms which occur together very frequently. Coupling refers to the interdependencies between modules, while cohesion describes how related the functions within a single module are. Low cohesion implies that a given module performs tasks which are not very related to each other and hence can create problems as the module becomes large. == Module coupling == Coupling in Software Engineering<ref name="Pressman_1982"/> describes a version of metrics associated with this concept. For data and control flow coupling: * '''d<sub>i</sub>''': number of input data parameters * '''c<sub>i</sub>''': number of input control parameters * '''d<sub>o</sub>''': number of output data parameters * '''c<sub>o</sub>''': number of output control parameters For global coupling: * '''g<sub>d</sub>''': number of global variables used as data * '''g<sub>c</sub>''': number of global variables used as control For environmental coupling: * '''w''': number of modules called (fan-out) * '''r''': number of modules calling the module under consideration (fan-in) <math>\mathrm{Coupling}(C) = 1 - \frac{1}{d_{i} + 2\times c_{i} + d_{o} + 2\times c_{o} + g_{d} + 2\times g_{c} + w + r}</math> <code>Coupling(C)</code> makes the value larger the more coupled the module is. This number ranges from approximately 0.67 (low coupling) to 1.0 (highly coupled) For example, if a module has only a single input and output data parameter <math>C = 1 - \frac{1}{1+0+1+0+0+0+1+0} = 1 - \frac{1}{3} = 0.67</math> If a module has 5 input and output data parameters, an equal number of control parameters, and accesses 10 items of global data, with a fan-in of 3 and a fan-out of 4, <math>C = 1 - \frac{1}{5 + 2\times 5 + 5 + 2\times 5 + 10 + 0 + 3 + 4} = 0.98</math> ==See also== * [[Connascence (computer science)]] * [[Coupling (physics)]] * [[Dead code elimination]] * [[Dependency hell]] * [[Efferent coupling]] * [[Inversion of control]] * [[List of object-oriented programming terms]] * [[Loose coupling]] * [[Make (software)]] * [[Static code analysis]] == References == {{Reflist|refs= <ref name="ISO_24765">ISO/IEC/IEEE 24765:2010 Systems and software engineering β Vocabulary</ref> <ref name="ISOIECTR19759_2005">ISO/IEC TR 19759:2005, Software Engineering β Guide to the Software Engineering Body of Knowledge (SWEBOK)</ref> <ref name="Stevens_1974">{{Cite journal |doi=10.1147/sj.132.0115 |title=Structured design |journal=[[IBM Systems Journal]] |volume=13 |issue=2 |pages=115β139 |date=June 1974 |author-last1=Stevens |author-first1=Wayne P. |author-link1=Wayne Stevens (software engineer) |author-last2=Myers |author-first2=Glenford J. |author-link2=Glenford J. Myers |author-last3=Constantine |author-first3=Larry LeRoy |author-link3=Larry LeRoy Constantine}}</ref> <ref name="Yourdon_1979">{{Cite book |title=Structured Design: Fundamentals of a Discipline of Computer Program and Systems Design |author-last1=Yourdon |author-first1=Edward |author-link1=Edward Yourdon |author-last2=Constantine |author-first2=Larry LeRoy |author-link2=Larry LeRoy Constantine |date=1979 |orig-year=1975 |publisher=Yourdon Press |isbn=978-0-13-854471-3 |bibcode=1979sdfd.book.....Y}}</ref> <ref name="Beck_2011">{{cite book |author-first1=Fabian |author-last1=Beck |author-first2=Stephan |author-last2=Diehl |chapter=On the Congruence of Modularity and Code Coupling |title=In Proceedings of the 19th ACM SIGSOFT Symposium and the 13th European Conference on Foundations of Software Engineering (SIGSOFT/FSE '11) |location=Szeged, Hungary |date=September 2011 |page=354 |doi=10.1145/2025113.2025162|isbn=9781450304436 |s2cid=2413103 }}</ref> <ref name="Arisholm_2004">{{cite journal |author-first1=Erik |author-last1=Arisholm |author-first2=Lionel C. |author-last2=Briand |author-link2=Lionel C. Briand |author-first3=Audun |author-last3=FΓΈyen |title=Dynamic coupling measurement for object-oriented software |journal=[[IEEE Transactions on Software Engineering]] |publisher=[[IEEE]] |volume=30 |number=8 |pages=491β506 |date=August 2004 |doi=10.1109/TSE.2004.41|hdl=10852/9090 |s2cid=3074827 |hdl-access=free }}</ref> <ref name="Pressman_1982">{{cite book |author-last=Pressman |author-first=Roger S. |author-link=Roger S. Pressman |date=1982 |title=Software Engineering - A Practitioner's Approach |publisher=McGraw-Hill |edition=4 |isbn=0-07-052182-4 |url-access=registration |url=https://archive.org/details/softwareengineer00pres_0 }}</ref> }} == Further reading == * {{Cite book |author-last=Myers |author-first=Glenford J. |author-link=Glenford J. Myers |title=Reliable Software through Composite Design |publisher=Mason and Lipscomb Publishers |location=New York |date=1974}} * {{Cite journal |author-first1=A. Jefferson |author-last1=Offutt |author-first2=Mary Jean |author-last2=Harrold |author-link2=Mary Jean Harrold |author-first3=Priyadarshan |author-last3=Kolte |title=A Software Metric System for Module Coupling |journal=[[Journal of Systems and Software]] |volume=20 |number=3 |pages=295β308 |date=March 1993|doi=10.1016/0164-1212(93)90072-6 }} * {{Cite book |author-first=Meilir |author-last=Page-Jones |title=The Practical Guide to Structured Systems Design |publisher=Yourdon Press |location=New York |date=1980 |isbn=978-8-12031482-5}} * {{Cite book |publisher=[[IEEE]] |title=Standard Glossary of Software Engineering Terminology |id=610.12_1990 |location=New York |date=1990 |isbn=0-7381-0391-8}} * {{Cite web |title=Curriculum for Certified Professional for Software Architecture (CPSA) - Foundation Level |publisher=International Software Architecture Qualification Board e.V. (ISAQB) |date=2015-05-15 |orig-year=2009 |version=3.01 |url=https://www.isaqb.org/wp-content/uploads/2015/05/isaqb-Curriculum-foundation-v3-MAY-2015-EN.pdf |access-date=2019-06-23 |archive-date=2017-03-29 |archive-url=https://web.archive.org/web/20170329132933/http://www.isaqb.org/wp-content/uploads/2015/05/isaqb-Curriculum-foundation-v3-MAY-2015-EN.pdf |url-status=dead }} [http://www.isaqb.org/wp-content/uploads/2015/05/isaqb-Lehrplan-foundation-v3-MAI-2015-DE.pdf] {{Webarchive|url=https://web.archive.org/web/20160222052330/http://www.isaqb.org/wp-content/uploads/2015/05/isaqb-Lehrplan-foundation-v3-MAI-2015-DE.pdf |date=2016-02-22 }} {{DEFAULTSORT:Coupling (Computer Science)}} [[Category:Programming principles]] [[Category:Object-oriented programming]] [[Category:Software architecture]] [[Category:Software metrics]]
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)
Pages transcluded onto the current version of this page
(
help
)
:
Template:Anchor
(
edit
)
Template:Citation needed
(
edit
)
Template:Cite book
(
edit
)
Template:Cite journal
(
edit
)
Template:Cite web
(
edit
)
Template:Reflist
(
edit
)
Template:Short description
(
edit
)
Template:Webarchive
(
edit
)