Coupling And Cohesion In Software Engineering Ppt

COUPLING

  1. Coupling And Cohesion In Software Engineering Ppt Presentation
  2. Coupling And Cohesion Example

Cohesion of a module gives the designer an idea about whether the different elements of a module belong together in the same module. Cohesion and coupling are clearly related. Usually the greater the cohesion of each module in the system, the lower the coupling between modules is. There are several levels of 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 in other parts of a program. Stated simply, a cohesive module should (ideally) do just one thing.!! Coupling is an indication of the relative interdependence among modules.!! Coupling and Cohesion. I believe the source of the terms Coupling and Cohesion is from a paper called, Structured Software Design (1974), Wayne Stevens, Glenford Myers, and Larry Constantine. This paper discusses characteristics of 'good' programming practices that can reduce maintenance and modification costs for software. Loose (Low) coupling.

An indication of the strength of interconnections between program units.

Highly coupled have program units dependent on each other. Loosely coupledare made up of units that are independent or almost independent.

Modules are independent if they can function completely without the presence ofthe other. Obviously, can't have modules completely independent of each other.Must interact so that can produce desired outputs. The more connectionsbetween modules, the more dependent they are in the sense that more infoabout one modules is required to understand the other module.

Three factors: number of interfaces, complexity of interfaces, type ofinfo flow along interfaces.

Software coupling and cohesion

Want to minimize number of interfaces between modules, minimize thecomplexity of each interface, and control the type of info flow. An interface of a module is used to pass information to and from other modules.

In general, modules tightly coupled if they use shared variables or if they exchange control info.

Loose coupling if info held within a unit and interface with other unitsvia parameter lists. Tight coupling if shared global data.

If need only one field of a record, don't pass entire record. Keep interfaceas simple and small as possible.

Two types of info flow: data or control.

  • Passing or receiving back control info means that the action of themodule will depend on this control info, which makes it difficult tounderstand the module.
  • Interfaces with only data communication result in lowest degree ofcoupling, followed by interfaces that only transfer control data. Highest ifdata is hybrid.
Coupling And Cohesion In Software Engineering PptAndRanked highest to lowest:
  1. Content coupling: if one directly references the contents of the other.

    When one module modifies local data values or instructions in anothermodule. (can happen in assembly language)

    if one refers to local data in another module.

    if one branches into a local label of another.

  2. Common coupling: access to global data.

    modules bound together by global data structures.

  3. Control coupling: passing control flags (as parameters or globals) sothat one module controls the sequence of processing steps in another module.
  4. Stamp coupling: similar to common coupling except that global variablesare shared selectively among routines that require the data. E.g., packagesin Ada. More desirable than common coupling because fewer modules will haveto be modified if a shared data structure is modified. Pass entire datastructure but need only parts of it.
  5. Data coupling: use of parameter lists to pass data items between routines.

COHESION

Measure of how well module fits together.

A component should implement a single logical function or single logical entity. All the parts should contribute to the implementation.

Many levels of cohesion:

Coupling And Cohesion In Software Engineering Ppt
  1. Coincidental cohesion: the parts of a component are not related butsimply bundled into a single component.

    harder to understand and not reusable.

  2. Logical association: similar functions such as input, error handling,etc. put together. Functions fall in same logical class. May pass aflag to determine which ones executed.

    interface difficult to understand. Code for more than one function may be intertwined, leading to severe maintenance problems. Difficult to reuse

  3. Temporal cohesion: all of statements activated at a single time, suchas start up or shut down, are brought together. Initialization, clean up.

    Functions weakly related to one another, but more strongly related to functions in other modules so may need to change lots of modules when do maintenance.

  4. Procedural cohesion: a single control sequence, e.g., a loop or sequenceof decision statements. Often cuts across functional lines. May containonly part of a complete function or parts of several functions.

    Functions still weakly connected, and again unlikely to be reusable in another product.

  5. Communicational cohesion: operate on same input data or produce sameoutput data. May be performing more than one function. Generally acceptableif alternate structures with higher cohesion cannot be easily identified.

    still problems with reusability.

  6. Sequential cohesion: output from one part serves as input for anotherpart. May contain several functions or parts of different functions.
  7. Informational cohesion: performs a number of functions, each with its ownentry point, with independent code for each function, all performed on samedata structure. Different than logical cohesion because functions not intertwined.
  8. Functional cohesion: each part necessary for execution of a singlefunction. e.g., compute square root or sort the array.

    Usually reusable in other contexts. Maintenance easier.

  9. Type cohesion: modules that support a data abstraction.

    Not strictly a linear scale. Functional much stronger than rest while firsttwo much weaker than others. Often many levels may be applicable whenconsidering two elements of a module. Cohesion of module considered ashighest level of cohesion that is applicable to all elements in the module.

Adam Carlson

COUPLING

An indication of the strength of interconnections between program units.

Highly coupled have program units dependent on each other. Loosely coupledare made up of units that are independent or almost independent.

Modules are independent if they can function completely without the presence ofthe other. Obviously, can't have modules completely independent of each other.Must interact so that can produce desired outputs. The more connectionsbetween modules, the more dependent they are in the sense that more infoabout one modules is required to understand the other module.

Coupling

Three factors: number of interfaces, complexity of interfaces, type ofinfo flow along interfaces.

Want to minimize number of interfaces between modules, minimize thecomplexity of each interface, and control the type of info flow. An interface of a module is used to pass information to and from other modules.

In general, modules tightly coupled if they use shared variables or if they exchange control info.

Loose coupling if info held within a unit and interface with other unitsvia parameter lists. Tight coupling if shared global data.

If need only one field of a record, don't pass entire record. Keep interfaceas simple and small as possible.

Two types of info flow: data or control.

  • Passing or receiving back control info means that the action of themodule will depend on this control info, which makes it difficult tounderstand the module.
  • Interfaces with only data communication result in lowest degree ofcoupling, followed by interfaces that only transfer control data. Highest ifdata is hybrid.
Ranked highest to lowest:
  1. Content coupling: if one directly references the contents of the other.

    When one module modifies local data values or instructions in anothermodule. (can happen in assembly language)

    if one refers to local data in another module.

    if one branches into a local label of another.

  2. Common coupling: access to global data.

    modules bound together by global data structures.

  3. Control coupling: passing control flags (as parameters or globals) sothat one module controls the sequence of processing steps in another module.
  4. Stamp coupling: similar to common coupling except that global variablesare shared selectively among routines that require the data. E.g., packagesin Ada. More desirable than common coupling because fewer modules will haveto be modified if a shared data structure is modified. Pass entire datastructure but need only parts of it.
  5. Data coupling: use of parameter lists to pass data items between routines.

Coupling And Cohesion In Software Engineering Ppt Presentation

COHESION

Measure of how well module fits together.

A component should implement a single logical function or single logical entity. All the parts should contribute to the implementation.

Many levels of cohesion:

  1. Coincidental cohesion: the parts of a component are not related butsimply bundled into a single component.

    harder to understand and not reusable.

  2. Logical association: similar functions such as input, error handling,etc. put together. Functions fall in same logical class. May pass aflag to determine which ones executed.

    interface difficult to understand. Code for more than one function may be intertwined, leading to severe maintenance problems. Difficult to reuse

  3. Temporal cohesion: all of statements activated at a single time, suchas start up or shut down, are brought together. Initialization, clean up.

    Functions weakly related to one another, but more strongly related to functions in other modules so may need to change lots of modules when do maintenance.

  4. Procedural cohesion: a single control sequence, e.g., a loop or sequenceof decision statements. Often cuts across functional lines. May containonly part of a complete function or parts of several functions.

    Functions still weakly connected, and again unlikely to be reusable in another product.

  5. Communicational cohesion: operate on same input data or produce sameoutput data. May be performing more than one function. Generally acceptableif alternate structures with higher cohesion cannot be easily identified.

    still problems with reusability.

  6. Sequential cohesion: output from one part serves as input for anotherpart. May contain several functions or parts of different functions.
  7. Informational cohesion: performs a number of functions, each with its ownentry point, with independent code for each function, all performed on samedata structure. Different than logical cohesion because functions not intertwined.
  8. Functional cohesion: each part necessary for execution of a singlefunction. e.g., compute square root or sort the array.

    Usually reusable in other contexts. Maintenance easier.

  9. Type cohesion: modules that support a data abstraction.

    Not strictly a linear scale. Functional much stronger than rest while firsttwo much weaker than others. Often many levels may be applicable whenconsidering two elements of a module. Cohesion of module considered ashighest level of cohesion that is applicable to all elements in the module.

Coupling And Cohesion Example

Adam Carlson