| Lesson 4 || Cohesion |
|Objective || Define cohesion. |
Define Cohesion in UML
- How big should an object be? How much information and behavior should be included in an object?
- Should I combine two small objects into one?
- Should I split a big object into smaller objects?
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
and applications. 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.
OO Analysis Cohesion - Quiz