Information Hiding


In the realm of software engineering, few principles are as foundational or as frequently misunderstood as Information Hiding (IH). While often confused with simply making variables “private,” IH is a sophisticated strategy for managing the overwhelming complexity inherent in modern software systems.

Historical Context

To understand why we hide information, we must look back to the mid-1960s. During the Apollo missions, lead software engineer Margaret Hamilton noted that software complexity had already surpassed hardware complexity. By 1968, the industry reached a “Software Crisis” where projects were consistently over budget, behind schedule, and failing to meet specifications. In response, David Parnas published a landmark paper in 1972 proposing a new way to decompose systems. He argued that instead of breaking a program into steps (like a flowchart), engineers should identify “difficult design decisions” or “decisions likely to change” and encapsulate each one within its own module.

The Core Principle: Secrets and Interfaces

The Information Hiding principle states that design decisions likely to change independently should be the “secrets” of separate modules. A module is defined as an independent work unit—such as a function, class, directory, or library—that can be assigned to a single developer. Every module consists of two parts:

  • The Interface (API): A stable contract that describes what the module does. It should only reveal assumptions that are unlikely to change.
  • The Implementation: The “secret” code that describes how the module fulfills its contract. This part can be changed freely without affecting the rest of the system, provided the interface remains the same.

A classic real-world example is the power outlet. The interface is the standard two or three-prong socket. As a user, you do not need to know if the power is generated by solar, wind, or nuclear energy; you only care that it provides electricity. This allows the “implementation” (the power source) to change without requiring you to replace your appliances.

Common “Secrets” to Hide

Successful modularization requires identifying which details are volatile. Common secrets include:

  • Data Structures: Whether data is stored in an array, a linked list, or a hash map.
  • Data Storage: Whether information is stored on a local disk, in a SQL database, or in the cloud.
  • Algorithms: The specific steps of a computation, such as using A* versus Dijkstra for pathfinding.
  • External Dependencies: The specific libraries or frameworks used, such as choosing between Axios or Fetch for network requests.