Thursday, December 16, 2010

Project 11 - Cohesion and Coupling


The next problem solving technique is Cohesion and Coupling. These terms are often contrasted with one another. They have an inverse relationship. Low coupling equals high cohesion and vice versa. According to Wikipedia, “Low coupling is often a sign of a well-structured computer system and a good design, and when combined with high cohesion, supports the general goals of high readability and maintainability.” Cohesion is defined as a measure of the internal statement of a method serve to accomplish the method’s purpose. Coupling is the degree to which one program module depends on the methods of another. In programming this can be seen in a simple Java color bar tool. I recently had to complete this color bar as a final assignment for my Java class. The first part of the program built the individual bars and color ranges with a color selector sliding bar. The second part of the program was tightly coupled with the first in that it really depended much on the methods in my first program. It did this by creating a swatch that showed the colors of various blends of blue, red, and green. Unfortunately, because this was so tightly coupled, a simple typo in my first program caused me major headaches in the second.

It’s very difficult for me to think of how this relates in real life. There are many inverse relationships in real life of course but with cohesion and coupling? I suppose a group of students studying for a test would show this relationship. One wants to have a high cohesion value when it comes to knowing the material at hand, and you would want to have a low coupling with the other students tests results. In other words one would not want other students grades and abilities affecting their own grades because you never know how well or not well others are doing academically. In terms of cohesion, in this scenario, since cohesion is defined as a measure of the internal statement of a method serve to accomplish the method’s purpose, assuming the method is “get an A on the final”. You would want the cohesion to be high.

References:
http://en.wikipedia.org/wiki/Coupling_(computer_science)

No comments:

Post a Comment