An impure layer is the application’s boundary with the external world. It performs side-effecting actions, connects application parts, and evaluates behavior declared in a pure layer. Keep it as small as possible so business logic remains easier to reason about. section 2.2.1
A useful architecture separates behavioral declarations from their execution. Business logic can describe scenarios using subsystem interfaces or DSLs, then translate those scenarios into impure code that operates over the interoperability layer. section 2.2.1 section 7.1.2
The separation gives each layer a clearer responsibility:
- The pure layer contains deterministic behavior and declares actions without evaluating them in an impure environment. section 2.2.1
- The impure layer may access the outer world and interpret the values or scripts produced by the pure layer. section 2.2.1
- State is allowed in both layers when represented purely, but impure state is restricted to the impure layer. section 7.1.2
Logging a sandwich recipe
A sandwich recipe can remain a declarative script while adding a logging instruction. The impure interpreter then performs the logging, reads and updates ingredient state, and handles missing ingredients by logging an error and failing. This keeps the recipe’s business sequence distinct from its operational effects. section 7.1.2
Figure 2.13 Layers: descriptions and responsibilities
Use the layer diagram to compare the responsibilities of pure, impure, business-logic, interoperability, and interface layers. section 2.2.1
