Software Engineering (2160701)

BE | Semester-6   Summer-2017 | 04/27/2017

Q3) (c)

Define Coupling and Cohesion.What is the difference between cohesion and coupling.

Coupling

Coupling between two modules is a measure of the degree of interdependence or interaction between the two modules. A module having high cohesion and low coupling is said to be functionally independent of other modules. If two modules interchange large amounts of data, then they are highly interdependent.

Cohesion

Cohesion is an indication of the relative functional strength of a module. A cohesive module performs a single task, requiring little interaction with other components. Stated simply, a cohesive module should (ideally) do just one thing.

Classification of Coupling

Data coupling

  • Two modules are data coupled, if they communicate through a parameter.
  • An example is an elementary (primal) data item passed as a parameter between two modules, e.g. an integer, a float, a character, etc.

Stamp coupling

  • This is a special case (or extension) of data coupling
  • Two modules (``A'' and ``B'') exhibit stamp coupling if one passes directly to the other a composite data item - such as a record (or structure), array, or (pointer to) a list or tree.
  • This occurs when Class B is declared as a type for an argument of an operation of ClassA

Control coupling

  • If data from one module is used to direct the order of instructions execution in another.
  • An example of control coupling is a flag set in one module and tested in another module.

Common coupling

  • Two modules are common coupled, if they share data through some global data items.
  • Common coupling can leads to uncontrolled error propagation and unforeseen side effects when changes are made.

Content coupling

  • Content coupling occurs when one component secretly modifies data that is internal to another component.
  • This violets information hiding – a basic design concept
  • Content coupling exists between two modules, if they share code.

Classification of Cohesion

Coincidental cohesion

  • A module is said to have coincidental cohesion, if it performs a set of tasks that relate to each other very loosely.
  • In this case, the module contains a random collection of functions.
  • It is likely that the functions have been put in the module out of pure coincidence without any thought or design.
  • For Ex., in a transaction processing system (TPS), the get-input, print-error, and summarize-members functions are grouped into one module.

Logical cohesion

  • A module is said to be logically cohesive, if all elements of the module perform similar operations.
  • For Ex., error handling, data input, data output, etc.
  • An example of logical cohesion is the case where a set of print functions generating different output reports are arranged into a single module.

Temporal cohesion

  • When a module contains functions that are related by the fact that all the functions must be executed in the same time span.
  • For Ex., the set of functions responsible for initialization, start-up, shutdown of some process, etc.

Procedural cohesion

  • If the set of functions of the module are all part of a procedure (algorithm) in which certain sequence of steps have to be carried out for achieving an objective
  • For Ex., the algorithm for decoding a message.

Communicational cohesion

  • If all functions of the module refer to the same data structure
  • For Ex., the set of functions defined on an array or a stack.

Sequential cohesion

  • If the elements of a module form the parts of sequence, where the output from one element of the sequence is input to the next.
  • For Ex., In a Transaction Processing System, the get-input, validate-input, sort-input functions are grouped into one module.

Functional cohesion

  • If different elements of a module cooperate to achieve a single function.
  • For Ex., A module containing all the functions required to manage employees’ pay-roll exhibits functional cohesion.

Cohesion

Coupling

Cohesion is the indication of the relationship within module. Coupling is the indication of the relationships between modules
Cohesion shows the module’s relative functional strength. Coupling shows the relative independence among the modules.
Cohesion is Intra – Module Concept. Coupling is Inter -Module Concept.
While designing you should strive for high cohesion i.e. a cohesive component/ module focus on a single task While designing you should strive for low coupling i.e. dependency between modules should be less.
Cohesion is the kind of natural extension of data hiding for example, class having all members visible with a package having default visibility. Making private fields, private methods and non-public classes provides loose coupling.