Cohesion and coupling

Before going any further, let me take a moment to define the terms cohesion and coupling. A component is said to be cohesive if it exhibits a high degree of functional relatedness with other related components. These related components (routines typically) should form cohesive program units (modules and classes). Every routine in a module should, for example, be essential for that module to accomplish its purpose. Generally, there are seven recognized levels of cohesion (none of which I’ll cover here). Coupling is an indication of the strength of the interconnections and interactions exhibited by different program components. If components are strongly coupled, they obviously have a large dependency on each other—neither can typically work without the other, and if you break one of the components, you’ll invariably break the others that are dependent on it. In Visual Basic, tight coupling typically comes about largely through the overuse and sharing of public symbols (variables, constants, properties, and routines exported by other units). Components that are highly cohesive yet loosely coupled are more easily shared. If code reuse is an issue, consider rigorously promoting both of these simple philosophies.