5 Encapsulation

Have you ever bought something significant, like a house, a plot of land, a company, or a car?

If so, you probably signed a contract. A contract stipulates a set of rights and obligations on both sides. The seller promises to hand over the property. The buyer commits to pay the specified amount at a prescribed time. The seller may give some guarantees as to the state of the property. The buyer may promise not to hold the seller liable for damages after the transaction completes. And so on.

A contract introduces and formalises a level of trust that would otherwise not be present. Why should you trust a stranger? It’s too risky to do that, but the institution of a contract fills the gap.

That’s what encapsulation is about. How ...

Get Code That Fits in Your Head: Heuristics for Software Engineering now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.