Book Deep-Read · A Philosophy of Software Design · Chapter 5
A Philosophy of Software Design · Ch 5 · Information Hiding (and Leakage) · Ousterhout · 2nd ed 2021
The previous chapter said good parts should be "deep": easy to use, doing lots of work behind the scenes. This chapter answers the obvious next question: how do you build a deep part? The answer is one of the oldest and best ideas in software: lock each "how it's done" secret in one place, and don't let it scatter. When you fill in a web form and hit "Submit," the program on the server gets your name with a single line of code. How it dug that name out of a long stream of bytes is something the app developer never has to know.
A program has three jobs: read a file, change a few things, write it back. The obvious split follows the steps: a "reader" part, a "changer" part, a "writer" part. Looks tidy. Then one day the file format changes, and you discover the reader and the writer both have to change; miss one and things break. Splitting by steps quietly split one secret into two copies.
When people write programs, the first thing that comes to mind is "what happens first, what happens next." So many systems get cut along the lines of a flowchart. The trouble is that several steps often need the same piece of knowledge: the same file format, the same shape of a network message. Once that knowledge is copied into several parts, it's like a recipe handed to three cooks: change the recipe and you must tell all three, and nobody warns you if you forget one.
It gives you a new question for carving up a system: not "how many steps is this," but "which decision here might change later, and who alone should guard it?" Split that way, each change lands in one place, and newcomers only need to learn the front door. One honest cost: hide too much and it backfires; if something the outside really needs is locked away, users are left stuck.
One secret lives in one part. Split by who needs to know what, not by what happens first.
Want to see what information hiding actually hides, why a private field is not information hiding, how to fix "back-door leakage," how temporal decomposition wrecks a student HTTP server step by step, why getParameter is a good interface, and where hiding goes too far? → Switch to Deep
You'd think module boundaries should follow "what happens first, what happens next"; Ousterhout says they should follow knowledge: each module encapsulates a few design decisions that others can't see and don't need to know. That is information hiding, the single most important technique for building deep modules. Its opposite is information leakage: the same design decision shows up in several modules, so changing it means changing all of them.
?, like ?q=book&page=2, commonly used to pass parameters.%20 or +; the server must decode them back.Chapter 5, right after Chapter 4's "Modules Should Be Deep": the previous chapter sets the goal, this one gives the main means. It inherits directly from David Parnas's classic 1972 paper and is taught through real mistakes Ousterhout saw grading student HTTP-server projects in his Stanford software design course (CS 190). Chapter 6 then asks how general-purpose an interface should be. In practice it maps to every review where someone asks, "should this class be split into a reader and a writer?"
Chapter 2 named change amplification as a key symptom of complexity: a seemingly simple change requires edits in many places. The root cause is often not messy code but the same knowledge held separately by several modules. Take a file format: the reading module knows it, the writing module knows it too. Add one field to the format and both must change; miss one, and the program may still compile, only to read back wrong data at runtime.
Worse, such dependencies are often invisible: neither class mentions the other in its interface, and nothing in the code structure shows they're tied together. This chapter asks: what exactly should a module hide? What counts as leakage? And why is the most natural split, "by steps," the one most likely to leak?
Ousterhout's typical "secrets": how to store data in a B-tree and access it efficiently; how to find the physical disk block for each logical block of a file; how to implement the TCP protocol; how to schedule threads on a multicore processor; how to parse JSON. A secret can be a data structure or algorithm, a lower-level detail (like a page size), or even a higher-level assumption (like "most files are small").
Information hiding cuts complexity from two directions:
A common misconception, dismantled on the spot: declaring a field private is not information hiding. Add a set of getters and setters that hand out the internal data as-is, and outside code still depends on its shape. The test is whether users need to know the decision, not whether the syntax lets them touch it.
Hiding can also be partial: if a feature is needed by only a few users and reached through separate methods, it is invisible to most users. Partial hiding still has value.
Leakage is the opposite of hiding: a design decision is reflected in more than one module, which creates a dependency between them; changing the decision means changing all of them. It comes in two forms:
Two fixes: if the affected classes are small and closely tied to the information, merge them into one class; otherwise pull the information out into a new class that alone owns it and exposes a simple interface that abstracts the details away. Replace the back door with a front door. "Information leakage" is one of the book's red flags: the same knowledge used in multiple classes.
Temporal decomposition splits a system by the order in which operations happen. Same example: a program reads a file, modifies it, writes it back, so it gets split into a reader class, a modifier class and a writer class. Reading and writing both need the file format, so that knowledge leaks into two classes.
Why is it so common? Because the order of execution is the first thing in your head when you write code, and flowcharts are naturally drawn as steps. The "first decomposition" Parnas criticized in 1972 is exactly this. Ousterhout's rule: when designing modules, focus on the knowledge needed to perform each task, not the order in which tasks occur. Order matters, and it should show up in some caller's code, but it should not decide module boundaries. Red flag: temporal decomposition.
The CS 190 assignment is a simplified HTTP server: receive requests, hand them to the application, send responses back. Ousterhout groups the students' most common mistakes, and they illustrate the chapter neatly.
Mistake one: reading and parsing as two classes. Many teams used one class to read a request off the network into a string and another to parse the string: textbook temporal decomposition. The catch: you can't know where to stop reading without parsing. The reader must find the end of the headers and read Content-Length to know how long the body is. So both classes must understand HTTP request structure; the format leaked, and callers must invoke two methods in a fixed order. Merged into one class, the code got shorter and the interface simpler. Hence a counterintuitive conclusion: information hiding can often be improved by making a class slightly larger, an echo of the previous chapter's attack on "smaller classes are always better."
Done well: the parameter interface. The best designs offered getParameter(name), returning an already-decoded string. It hides two things: a parameter may come from the query string in the request line or from the body, and its value must be URL-decoded (for example + becomes a space). The application developer needs to know neither. The counterexample: some teams returned their internal Map<String, String> directly. That's shallow and exposes the internal representation, so changing how parameters are stored would ripple into every caller. Better still to add getIntParameter(name), which also hides the integer conversion and its error checking.
Mistake two: no defaults. Some teams required callers to specify the HTTP protocol version when building a response. The response version should simply match the request's, and the class can do that by itself. Ousterhout's principle: defaults are partial information hiding and should make the common case as simple as possible; a class should "do the right thing" without being asked, and the best features are the ones you get without even knowing they exist. Red flag: overexposure, when the API for a commonly used feature forces users to learn about features that are rarely used.
Information hiding isn't only between classes. It applies inside a class too: design private methods so that each encapsulates some piece of information or capability, and minimize the number of places where each instance variable is used. The fewer places touch a variable, the fewer dependencies inside the class.
But you can hide too much. Hiding only makes sense when the information isn't needed outside the module. If a configuration parameter strongly affects performance and users genuinely need to tune it for their situation, it must be exposed. Ousterhout's ideal is a module that computes the best setting itself (better not to expose it at all); when that's impossible, recognize honestly which information the outside needs, and expose as little as possible. This is the same line as Chapter 4's "false abstraction": hide what's unimportant, expose what's important.
Table 1 · Two ways to decompose
| Approach | Boundaries follow | Example | Cost |
|---|---|---|---|
| Temporal | Execution order: read, then modify, then write | Reader + parser; reader + writer | Knowledge held in several copies; one decision change touches many places; callers must remember call order |
| By knowledge | Design decisions: who knows the format, who knows the protocol | One HTTPRequest class; one file-format class | Individual classes get bigger; you must first think about which decisions may change, which is harder than following a flowchart |
Table 2 · Fixing leakage once you find it
| Situation | Fix | Cost / caution |
|---|---|---|
| Two small classes share one piece of knowledge | Merge them | Bigger class; only when both are tightly tied to that knowledge |
| Several large classes depend on it | Extract a new class that alone owns it, behind an abstract interface | One more module; the new interface must really be simpler than the details, or the leak just moves |
| Internal representation handed out (a Map, getters for everything) | Replace with query methods (getParameter) | A few more methods; but callers don't change when the implementation does |
| Callers forced to pass an almost-always-same value | Provide a default; the few can override | A bad default is inherited by everyone; pick the true common case |
| Information the outside really needs (e.g. performance knobs) | Don't hide it; auto-tuning is better still | Every exposed item makes the interface heavier; expose only what's needed |
One rule of thumb: before drawing boundaries, list the decisions likely to change, and give each exactly one owner. If any change request makes you say "this means editing both A and B," there's a leak between A and B.
In interviews and design reviews, "information hiding" beats "encapsulation" because you can test it: if the format, protocol, or storage changed tomorrow, how many files would you touch? More than one means a leak. The same question scales up to services (an extension, not from the book): two microservices reading and writing the same database table is back-door leakage across services; neither API mentions the other, and a schema change breaks both.
Evidence and sources · publicly verifiable
Request.FormValue returns the first value for the named component, merging three sources in a fixed precedence: a URL-encoded form body (POST, PUT, PATCH only), query parameters, and a multipart form body. The caller writes one line. Source: pkg.go.dev · net/http (Request.FormValue)WriteHeader hasn't been called, Write calls WriteHeader(http.StatusOK) first; if there's no Content-Type header, it infers one from the first 512 bytes; and automatic headers such as Date are added unless you explicitly set them to nil. That's "do the right thing without being asked." Source: pkg.go.dev · net/http (ResponseWriter)① Information hiding is the main way to build deep modules: each module encapsulates a few design decisions others can't see.
② It cuts complexity two ways: simpler interfaces, and easier evolution (a decision change touches one module).
③ Private fields ≠ information hiding; getters and setters that expose internal structure still leak.
④ Leakage = one decision reflected in several modules; back-door leakage (invisible in interfaces) is the most pernicious.
⑤ Fix: merge small classes, or extract the knowledge into a new class with a simple interface, turning the back door into a front door.
⑥ Temporal decomposition is the most common trap: split by the knowledge each task needs, not the order tasks occur.
⑦ HTTP case: merge reading and parsing; getParameter hides parameter source and URL decoding; returning the internal Map is the counterexample.
⑧ Defaults are partial hiding: make the common case zero-config, have classes do the right thing unasked; overexposure is a red flag.
⑨ Don't over-hide: expose what the outside truly needs, and auto-tune when you can.