Cohesion and Coupling Concept in Programming:
The concepts of Cohesion and Coupling are both used as a software metric. This means that a piece of software or programs structure can be somewhat measured against these concepts to determine the quality of said structure.
Coupling and Cohesion play somewhat of a balancing act between each other, as to little of one tends to mean more of the other.
This does not mean that they are equal. In fact, a good program (that is being measured for difficulty in maintainability) does not want to have high Coupling.
Much like it sounds, Coupling is dependency. In computer science, this dependency is around modules and how much they rely on other modules to perform functions. One can conclude that the higher the coupling, the more co-dependent the module.
Cohesion does not mean that each module does not need the other, but rather that it doesn't need the other to do its very own task. Good cohesion places modules together that can work perform a single task by doing their own job.
When it comes to troubleshooting an issue within a program, it is easier to locate the issue in modules that are independent that it is to locate the issue within modules that rely on other modules to produce their own outcomes.
Cohesion and Coupling Concept outside of Programming:
This is fun, as it hits close to home. By studying this concept in programming, I was able to better understand my marriage, job, and studies--go figure.
As mentioned in the previous section, Coupling can be viewed as co-dependency. I can't prove it, but I think that is where "Couple" originated. My wife and I are what we call a happily co-dependent couple, but the truth is that we have moved away such a high level of Coupling, in favor of higher Cohesion.
Earlier in our relationship, we used to divvy up the chores as follows (with the end goal being a clean house:
Le' Darien's Chores:
- Wash laundry
- Empty Dishwasher
- Throw out the trash.
- Hang-up clothes or place them in drawers.
April's Chores:
- Gather laundry
- Fill dishwasher
- Sweep/vacuum
- Fold clothes or place on hangers
We could never figure out why are house was not clean, nor why it was such a chore to get the single task done. The answer is that we created a process with an extremely high rate of Coupling.
If April didn't gather the laundry, I couldn't wash it. If I didn't empty the dishwasher, she couldn't load it. It would be a waste if I took out the trash before we could unload the dirt into it.
This meant that all of our duties were dependent on the results of another's completion of duties.
Now, we are more of a cohesive unit when it comes to housework.
Le' Darien's Chores:
- Dishes:
- Empty clean dishes from dishwasher and put them away.
- Gather dirty dishes and put them in the dishwasher.
- Turn on the dishwasher.
- Empty clean dishes from dishwasher and put them away.
- Trash duty:
- Dust and sweep
- Gather all trash into trash can
- Take out the trash.
- Dust and sweep
April's Chores:
- Clothes:
- Gather laundry to be washed.
- Take laundry to mat and wash/dry
- Fold or hang clean laundry
- Gather laundry to be washed.
By performing our own duties, independent of one another, we are better using are resources and are more efficient, as we don't rely on one another to get our jobs done.
The added (unfortunate) benefit is that if something doesn't get done…she knows who to blame.
No comments:
Post a Comment