Imagine you are building a complex model of a starship. You have two choices for how you assemble the thousands of tiny pieces.
You take every piece (the engine, the wings, the cockpit) and permanently fuse them together with industrial-strength super glue. The final model looks correct, and it's certainly solid. But what happens when you realize you put the left wing on upside down? Or you want to upgrade the engine piece with a newer, more detailed one? You can't. To change one small part, you risk destroying the entire structure. The pieces are intensely and rigidly connected.
Each piece is a self-contained unit with a standard, well-defined connection point. The engine block clicks neatly onto the main fuselage. The wings snap into place. The cockpit can be easily removed and inspected. If you want to swap the engine, you simply pop it off and click the new one in. The individual pieces are robust and focused on their own function, and their interaction is standardized and flexible.
In software design, these two approaches represent the extremes of a fundamental concept. The super-glued model is a system with high coupling and low cohesion. The LEGO model is a system with low coupling and high cohesion.
Mastering object-oriented design is a quest to understand and control these two powerful, opposing forces. Cohesion is the force that holds a single module together, while coupling is the force that pulls different modules together. This chapter will explore these twin principles, demonstrating how their balance dictates whether you are building a brittle, disposable model or an elegant, resilient system.