You are on page 1of 5

Coupling Cohesion and Coupling

The amount of interaction between components in a system

1/2009

Indications of Coupling

Coupling Types
Content coupling Common coupling External coupling Control coupling Stamp coupling Data coupling Message coupling Subclass coupling Uncoupled

Content coupling
One component depends on the internal workings of another:

Common Coupling
Coupling via shared data
Global data structures Common blocks

Common Coupling
Coupling via shared data
Global data structures Common blocks

External Coupling
Two components share something externally imposed
Data format Communication protocol Device interface

Control Coupling
Component passes control parameters to coupled components. May be either good or bad, depending on situation.

Stamp Coupling
Component A passes a data structure to component B B only uses part of the data

Data Coupling
Component A passes data to component B Not the same as Stamp Coupling:
Data (a representation), not a data structure (an implementation).

Message Coupling
Components communicate only through a public interface Messages are parameterless (events)

Uncoupled
Completely uncoupled components are not systems. Systems are made of interacting components.

Key Idea in Object-Oriented Programming

Coupling Types
Content coupling Common coupling External coupling Control coupling Stamp coupling

Cohesion
The degree to which all elements

Data coupling Message coupling Subclass coupling Uncoupled

Types of Cohesion: low to high


Coincidental Logical Temporal Procedural Communicational Sequential Informational Function low

Coincidental Cohesion
Accidental Worst form

high

Logical Cohesion
Several logically related elements are in the same component. Not related functionally, but related logically.

Temporal Cohesion
Elements of a component are related by timing Elements are grouped by when they are processed

Procedural Cohesion
Elements of a component are related only to ensure a particular order of execution Common for input and output to be unrelated Common to pass partial results Control flows between modules Actions are still weakly connected and unlikely to be reusable

Communicational Cohesion
Elements of a component are related by the data that they process Component performs a series of actions related by a sequence of steps to be followed. All actions are performed on the same data.

Sequential Cohesion
The output of one component is the input to another. Good situation

Informational Cohesion
Module performs a number of actions, each with its own entry point, with independent code for each action, all performed on the same data.

Functional Cohesion
Every essential element to a computation is contained in the component. Every element in the component is essential to the computation. Ideal situation.

Cohesion

Techniques for Improving Design


Reduce complexity
Think. Abstract. Be clever.

Design by contract
Contract: Agreement between two parties Mutual obligations (pre conditions) Benefits (post conditions) Consistency (invariants)

Prototype design

You might also like