Cohesion is a measure of the degree to which all the parts of an object support a single purpose.
High cohesion means that all the elements in the object support the same purpose.
Low cohesion means that different elements support different purposes.
Cohesion may be applied to any entity, not just objects which include operations, applications, components, subsystems, and systems.
As an illustration, imagine you have the job description programmer. When all your duties relate to programming, you are very productive.
But what happens when you are assigned other, less-related duties, like serving on a standards committee?
What happens to your productivity?
Objects are much the same. When objects have to handle multiple responsibilities, they become less flexible, incur the overhead of juggling unrelated tasks, and work less efficiently.
Organizations that require maximum flexibility and responsiveness tend to have the highest cohesion. Consider the military.
Each person has a specific rank and job. Teams can be assembled at a moments notice. Members can be swapped in and out without disrupting the operation.
Objects are much the same. High cohesion, a single purpose for each object, supports the rapid assembly of objects to create new components
The cohesion principle applies equally to all levels of modeling abstraction, from objects to components to applications to subsystems to
So, with these things in mind, the answers to the questions listed at the beginning of this lesson are:
How much information should be included in an object? Answer: Only the information needed to support the object's single purpose.
When should you split an object? Answer: When the object is responsible for more than one purpose.
When should you merge multiple objects? Answer: When objects become fragmented and cannot fulfill a purpose without constantly asking
for help from another object.
Click the Quiz link below to take a short multiple-choice quiz on cohesion.
OO Analysis Cohesion - Quiz