9.1. Coupling and Cohesion
Of all of the fancy terms associated with object orientation, two of the simplest are too often forgotten. In fact, any discussion on inheritance, polymorphism, or composition is really talking about coupling and cohesion. Informal definitions for these terms follow:
Coupling: The degree to which classes within our system are dependent on each other.
Cohesion: The measure of how much an entity supports a singular purpose within a system.
Our goal when designing a system should be to reduce coupling and increase cohesion. A system that is loosely coupled implies the number of relationships among all classes in our system has been kept to the minimum. Obviously, classes must have relationships to each other; otherwise, ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access