madhavrao… » Coupling

Coupling

Coupling: Its measure of how strongly one element is connected to, has knowledge of, or relies on other elements. An element with low (or weak) coupling is not dependent on too many other elements. A class with with high coupling relies on many other classes. Such classes may be undesirable; some suffer from the following problems:

  • Changes  in related classes forces changes
  • Harder to understand in isolation
  • Harder to reuse because its use requires the additional presence of the classes on which it depends

Types of Coupling

Types of coupling in order of highest to lowest are as following:
(This also includes procedural coupling)

  • Content Coupling
  • Common Coupling
  • External Coupling
  • Control Coupling
  • Stamp Coupling
  • Data Coupling
  • Message Coupling
  • Subclass Coupling
  • Temporal Coupling

Content Coupling (high): Content coupling is when one module modifies or relies on the internal workings of another module. Therefore changing the way the second module produces data will lead to changing the dependent module. In OOP improper implementation of AOP can creep in this type of coupling.

Common Coupling: Common coupling is when two modules share the same global data. Changing the shared resource implies changing all the modules using it. Enumerations, Constants are few constructs which should be looked into for this type of coupling in OOP

External Coupling: External coupling occurs when two modules share an externally imposed data format, communication protocol, or device interface. Interfacing technology should be decoupled from main application by using Adapter pattern to overcome this type of coupling.

Control Coupling: Control coupling is one module controlling logic of another by passing it information on what to do. Class members should be made private, they should be exposed using public accesses. If any variable is used for controlling logic of the class, then it should be modified by methods of the class and avoid exposing them with public accesses.

Stamp Coupling: Stamp coupling exists when module shares a composite data structure and uses only part of it. 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 for example; parameters. Chang in data structure all related modules.

Message Coupling (low): This is loosest type of coupling. Modules are not dependent on each other, instead they use public interface to exchange parameter less messages (or events)

Subclass Coupling: Describes relationship between a class and its parent. The class is connected to its parent, but the parent isn’t connected to child.

Temporal Coupling: When two actions are bundled together into one module just because they happen to  occur at same time then it leads to temporal coupling.

Leave a comment

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <blockquote cite=""> <code> <em> <strong>