Cohesion is having code that work on a single well-defined task, or work on the same set of data, grouped at one place, within a class or package / module.
Coupling is how closely different modules interact with each other.
Loose coupling and strong cohesion is desired: code that work on a single task should remain together, and code that work on different tasks should remain away from each other, and interact via well defined interfaces.
Now we have some code in our front-end/web module that performs some specific task.
We are introducing a scheduler module that will need some code from the web module.
To promote loose coupling, the web module and the scheduler module need to be separate. However to promote strong cohesion, the code needs to be in the same place, which in turn requires that web module and scheduler module gets tightly coupled.
Not that we don't have a solution. We need to refactor the code in a separate module and have the web module and scheduler module have dependencies on it. So the web module and scheduler module will remain decoupled. But strong cohesion in the code in question will still exist.
No comments:
Post a Comment