Coupling (computer science)

From Wikipedia, the free encyclopedia

(Redirected from Subclass coupling)
Jump to: navigation, search

In computer science, coupling or dependency is the degree to which each program module relies on each one of the other modules.

Coupling is usually contrasted with cohesion. Low coupling often correlates with high cohesion, and vice versa. The software quality metrics of coupling and cohesion were invented by Larry Constantine, original developer of Structured Design (see also SSADM).

Contents

Coupling can be "low" (also "loose" and "weak") or "high" (also "tight" and "strong"). Low coupling refers to a relationship in which one module interacts with another module through a stable interface and does not need to be concerned with the other module's internal implementation (see Information Hiding). With low coupling, a change in one module will not require a change in the implementation of another module. Low coupling is often a sign of a well-structured computer system, and when combined with high cohesion, supports the general goals of high readability and maintainability.

Systems that do not exhibit low coupling might experience the following developmental difficulties:

  • Change in one module forces a ripple of changes in other modules.
  • Modules are difficult to understand in isolation.
  • Modules are difficult to reuse or test because dependent modules must be included.

The concept of coupling is usually related to the concept of cohesion: low coupling facilitates high cohesion, and vice versa. For example, one approach to increasing cohesion is functional design, which seeks to limit the responsibilities of modules along functionally-related boundaries. Modules with single responsibilities tend to communicate less with other modules, which typically causes the side-effect of reduced coupling. This can also be seen in object-oriented programming, where coherence is said to increase when classes are re-factored to contain more closely-related code. This tends to cause the connections between the classes to become less dependent on their internal implementations, which results in reduced coupling. Specifically, 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 which references B (via return type or parameter).
  • A is a subclass of (or implements) class B.

Low coupling may also reduce performance, and a highly-coupled system is sometimes desirable to achieve maximum efficiency. Regardless, in many modern computing systems, the cost of reduced performance is often seen as a worthy trade for the benefits to the software development process that result from low coupling.[citation needed]

Some types of coupling, in order of highest to lowest coupling, are as follows:

Content coupling (high)
Content coupling is when one module modifies or relies on the internal workings of another module (e.g. accessing local data of another module).
Therefore changing the way the second module produces data (location, type, timing) will lead to changing the dependent module.
Common coupling
Common coupling is when two modules share the same global data (e.g. a global variable).
Changing the shared resource implies changing all the modules using it.
External coupling
External coupling occurs when two modules share an externally imposed data format, communication protocol, or device interface.
Control coupling
Control coupling is one module controlling the logic of another, by passing it information on what to do (e.g. passing a what-to-do flag).
Stamp coupling (Data-structured coupling)
Stamp coupling is when modules share a composite data structure and use only a part of it, possibly a different part (e.g. passing a whole record to a function which only needs one field of it).
This may lead to changing the way a module reads a record because a field which the module doesn't need has been modified.
Data coupling
Data coupling is when modules share data through, for example, parameters. Each datum is an elementary piece, and these are the only data which are shared (e.g. passing an integer to a function which computes a square root).
Message coupling (low)
This is the loosest type of coupling. Modules are not dependent on each other, instead they use a public interface to exchange parameter-less messages (or events).


In object-oriented programming,

subclass coupling : describes the relationship between a class and its parent. The class is connected to its parent, but the parent isn't connected to the child.

Also consider:

Temporal coupling
When two actions are bundled together into one module just because they happen to occur at the same time.

High cohesion and low coupling are attributes of good design.

Coupling in Software Engineering [1] describes a version of metrics associated with this concept.

For data and control flow coupling:

 di = number of input data parameters
 ci = number of input control parameters
 do = number of output data parameters
 co = number of output control parameters

For global coupling:

 gd = number of global variables used as data
 gc = 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)

Coupling (C) = 1 - 1/(di + 2·ci + do + 2·co + gd + 2·gc + w + r)

 "1 - ..." makes the value larger the more coupled the module is.  This number 
 ranges from approximately 0.66 (low coupling) to 1.0 (highly coupled)

For example, if a module has only a single input and output data parameter

C = 1 - 1/(1+0+1+0+0+0+1+0) = 1 - 1/3 = 0.67

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,

C = 1 - 1/(5 + 2·5 + 5 + 2·5 + 10 + 0 + 3 + 4) = 0.98

Very loosely coupled systems have the added advantage that they tend to build more quickly. This is due to the low amounts of inter-module dependency. Systems such as CORBA or COM allow objects to communicate with each other without having to know anything about the other's implementation. Both these systems even allow for objects to communicate with objects written in other languages. The fact that the objects may be built independently reduces the amount of recompilation required when changes are applied.

  1. ^ Pressman, Roger S. Ph.D (1982). Software Engineering - A Practitioner's Approach - Fourth Edition. ISBN 0-07-052182-4

  • SemmleCode - A code querying tool, with a large library of software metrics, including metrics to compute coupling. Find detailed descriptions of metrics with their clear and concise definition in an object-oriented query language and their corresponding references.
Advanced Search
Included Web Search Engines


Safe Search

close

Top Matching Results

Occasionally Search.com will highlight specialized results that are based on the context of your query. Examples of specialized results include specific links to news, images, or video.

Top Matching Results may highlight information from other Search.com pages, content from the CNET Network of sites, or third party content. The listings are based purely on relevance. Search.com does not receive payment for listings in this section but our partners that provide this data may get paid for listing these products.

Sponsored Links

This section contains paid listings which have been purchased by companies that want to have their sites appear for specific search terms and related content. These listings are administered, sorted and maintained by a third party and are not endorsed by Search.com.

Search Results

Search.com sends your search query to several search engines at one time and integrates the results into one list which has been sorted by relevance using Search.com's proprietary algorithm. You can customize the list of search engines included in your metasearch from the preferences.

The search engines that are used in your metasearch may allow companies to pay to have their Web sites included within the results. To view the Paid Inclusion policy for a specific search engine, please visit their Web site. Search.com does not accept payment or share revenue with any search engine partner for listings in this section.