3.2 Coupling and Cohesion

   

Coupling and cohesion are terms used to describe the effective modularity of a component. They are central to designing robust, maintainable , and reusable software.

Dictionary Definitions

Cohesion 1 the act or condition of sticking together; 2 a tendency to cohere; 3 Physics the sticking together of molecules of the same substance

Coupling 1 That which connects

Software Academia Definitions

Cohesion ” A measure of how strongly the elements within a module are related . The stronger the better.

The idea of cohesion in software design first appeared in the mid-1960s, courtesy of Larry Constantine. The term was acquired from sociology, where it applies to the relatedness of humans within groups. For our purposes we can think of cohesion as collecting all similar functionality in one component.

Coupling ” A measure of the degree of independence between modules. When there is little interaction between two modules, the modules are described as loosely coupled. When there is a high degree of interaction, the modules are described as tightly coupled .

There are various types of coupling and cohesion defined, but this is outside the scope of this book. In a well-designed component we are looking for loose coupling and strong cohesion.

Now that that's cleared up, back to the factory. Consider that the top-level processes for the factory are deliver a Widget, deliver a SuperWidget, deliver a MegaWidget 2000, and finally deliver a Widgetometer. Each subprocess is dependent on various other subprocesses, and each production line is intertwined with all the others. This is tight coupling. A symptom of tight coupling is the movement of parts and subassemblies around the shop floor, which is closely analogous to the data in software. Each department in the factory is not single-mindedly producing for one production line. It would be very difficult to establish what work is being done where. This is weak cohesion.

It can be seen in Figure 3.2, that by reorganizing the factory into flow lines for each product type and storing parts on the line at the point where they are to be used, the following improvements are made:

Movement of products, parts, subassemblies, and people around the factory has been reduced.

Management of the production lines has been simplified.

Figure 3.2. Reorganized factory.

graphics/03fig02.jpg

The flow line principle turns each production line into a minifactory, independent and unaffected by any other areas of the shop floor. A production line could be removed, modified, or added without affecting any of the others. Production lines therefore exhibit very strong cohesion and are loosely coupled to one another. As described earlier, the factory is analogous to a software application and the production lines are individual components . The internal production line processes could be thought of as private subroutines and the parts as data.

Now consider the following. When you accelerate your car, you are not thinking about how the gasoline is pulled from the tank into the cylinders where it ignites, pushing the piston down, which turns the crankshaft faster, which turns the gears faster, which then turns the driveshaft, which transmits power to the wheels. When you steer, you don't think about the power steering, or for that matter braking and changing gears. Cars are very complex, but as far as the user is concerned this complexity is hidden away behind a simple interface. Not only is it a simple interface but it's a fairly common interface, and luckily automobile manufacturers have agreed on its format and stuck to it. We could otherwise find ourselves in the following situation.

The diagrams in Figure 3.3 illustrate four possible ways of controlling a vehicle; they are four interfaces to the services provided by the vehicle. Transferring from one mode to another would involve learning a new combination of controls. This would not only be tiresome but could be dangerous. The likelihood of an accident is greatly increased during the learning phase.

Figure 3.3. Possible car interfaces.

graphics/03fig03.gif


   
Top


A Software Engineering Approach to LabVIEW
A Software Engineering Approach to LabVIEW
ISBN: 0130093653
EAN: 2147483647
Year: 2003
Pages: 66

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net