16-01-2013, 11:55 AM
Coupling and Cohesion
Coupling.ppt (Size: 306.5 KB / Downloads: 24)
Content coupling
Definition: One component references contents of another
Example:
Component directly modifies another’s data
Component refers to local data of another component in terms of numerical displacement
Component modifies another’s code, e.g., jumps into the middle of a routine
Common Coupling
Definition: Two components share data
Global data structures
Common blocks
Usually a poor design choice because
Lack of clear responsibility for the data
Reduces readability
Difficult to determine all the components that affect a data element (reduces maintainability)
Difficult to reuse components
Reduces ability to control data accesses
Control Coupling
Definition: Component passes control parameters to coupled components.
May be either good or bad, depending on situation.
Bad when component must be aware of internal structure and logic of another module
Good if parameters allow factoring and reuse of functionality
Stamp Coupling
Definition: Component passes a data structure to another component that does not have access to the entire structure.
Requires second component to know how to manipulate the data structure (e.g., needs to know about implementation)
May be necessary due to efficiency factors: this is a choice made by insightful designer, not lazy programmer.
Data Coupling
Definition: Two components are data coupled if there are homogeneous data items.
Every argument is simple argument or data structure in which all elements are used
Good, if it can be achieved.
Easy to write contracts for this and modify component independently.
Coincidental Cohesion
Definition: Parts of the component are only related by their location in source code
Elements needed to achieve some functionality are scattered throughout the system.
Accidental
Worst form
Temporal Cohesion
Definition: Elements of a component are related by timing.
Difficult to change because you may have to look at numerous components when a change in a data structure is made.
Increases chances of regression fault
Component unlikely to be reusable.