TechWorkRamblings

by Mike Kalvas

202312091449 Encapsulate at the boundary

#new

We should code systems that encapsulate external systems at the boundaries of our system.

For example, if I'm building an app that consumes an API, I should encapsulate the specifics of the API at the very edge of my system. This is a translation layer that turns the calling and results of the API into a shape that I control.

This is a particularly powerful — and nearly required — pattern when working with type systems. We take in values that are unknown, spend the effort to well-type them at the boundary, and then the rest of our app does not need to check if that external value was good or not since they only use the internal representation. Using this pattern, you only 202312091445 Rely on what you control

See also: 202205121023 Use values as the boundary