Component Cohesion

Clean Code, Episode 16

By Uncle Bob

55 minJan 2013

Sticky, Icky, gooey! Cohesion. That's what this one's all about. Component Cohesion.

How and why do components cohere? What are the good forces of component cohesion, and what are the bad forces? Which classes belong together in components, and which should be kept apart?

Oh, and why do White Dwarf stars go Supernova?

In this episode we're going to explore the three principles of component cohesion:

  • The Release Reuse Equivalence principle
  • The Common Closure Principle
  • The Common Reuse Principle

We'll learn about the goal of independent deployability, and why that goal causes certain classes to belong together, while other classes don't.

We'll also learn about the forces of false cohesion that tempt us to group classes together into ineffective components that aren't independently deployable.

We'll see, first hand, the erie connection between the component principles and the SOLID principles.

We'll see how components are governed by release procedures, by actors and their responsibilities, and also by how much knowledge they present to their users.

And we'll discover that the component structure of a system is a function of it's maturity as well as of it's behavior. We'll see that the component principles have a certain mutual exclusivity that creates a tension in the component structure.

So get a rag and some Acetone, because we've got a lot of gooeyness to deal with, as we slurp our way through the topic of component cohesion.