11. Hide information

Summary

Don’t tell: Don’t expose internal information from an entity that provides an abstraction.

Discussion

To minimize dependencies between calling code that manipulates an abstraction and the abstraction’s implementation(s), data that is internal to the implementation must be hidden. Otherwise, calling code can access—or, worse, manipulate—that information, and the intended-to-be-internal information has leaked into the abstraction on which calling code depends. Expose an abstraction (preferably a domain abstraction where available, but at least a get/set abstraction) instead of data.

Information hiding improves a project’s cost, schedule, and/or risk in two main ways:

It localizes changes: Information hiding reduces ...

Get C++ Coding Standards: 101 Rules, Guidelines, and Best Practices 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.