Lesson 3 of 7 · 3 min read
SOLID through five change requests
Treat each principle as a way to evaluate an actual change. The notification worker has to respect consent, choose a channel, persist plans and report outcomes.
Single responsibility and independent changes
A privacy policy update changes when a reminder may be planned. A storage migration changes how its timestamp is encoded. If both edits land in the same function, consider separating consent evaluation from row mapping. Keep related operations together when they enforce the same rule. The number of methods in a class says little about how many independent decisions can cause it to change.
Open for the extension you expect
When a second delivery channel appears, move channel-specific formatting and submission behind the same capability. Register an adapter in the startup wiring and let the scheduling policy continue to call that capability. This protects the scheduler against adding channels with the same contract. A channel that needs replies introduces a new capability and can justify a change to the use case. Keep an exhaustive switch for a small, intentionally closed set such as plan status.
Liskov substitution and observable promises
A send adapter promises that accepted means the provider accepted a request, and retryable means the worker can retry using the same idempotency key. An implementation with the same type can still label permanent rejection retryable or claim accepted before making the request. The caller’s guarantees then break. Test identical valid inputs, result meanings and behavior on repeated requests where the contract guarantees it. A test double has to preserve the observable guarantees used by the test.
Interface segregation by caller
The notification history page needs a read operation. The worker needs to record a delivery outcome. Give each caller a contract for its own work. One database adapter can satisfy both. If constructing it still initializes an unused external provider, segregating types alone does not remove that cost. Split construction when the extra dependency causes a real cost or mixes lifetimes.
Dependency inversion across the module boundary
The application defines a Delivery capability using its own message and result vocabulary. The provider adapter imports that contract, translates the request and interprets provider results. The application can then change provider without importing its SDK. Wiring still chooses a concrete adapter. Using a TypeScript interface exported by the SDK would keep the core coupled to SDK decisions. Plain domain values and stable helpers need no extra interface merely to satisfy a rule.
Name the change a principle helps contain, then test the behavior the boundary must preserve.
async function notifyLearner(message, channel) {
// The channel promises a receipt or rejects.
// It must never report success for an unsent message.
return await channel.deliver(message);
}