liveBook · Manning

Imperative shell

As explained in Data-Oriented Programming in Java

An architectural pattern that isolates deterministic computation in a functional core and places side effects and nondeterministic interactions in an imperative shell.

An imperative shell isolates side effects and nondeterministic interactions around a deterministic functional core. Dependency arrows point outward: the core computes from supplied data, while the shell reads services, time, files, and APIs. section 6.2 section 10.4.3

Separate responsibilities by asking what each operation depends on:

  • Keep parsing, data construction, and business rules in deterministic functions that accept inputs and return outputs. section 10.4.3
  • Place database reads, cloud storage, clocks, random values, and external service calls in the imperative shell. section 6.2
  • Test the core with ordinary inputs and outputs, reserving mocks and integration setup for the shell boundary. section 11.2

Refactoring a cloud-backed repository

Instead of making loadAccounts download bytes, parse CSV, and construct Accounts in one method, let the shell read the resource and delegate parsing: return FileRepository.parse(this.read(resource)). The static parse method then transforms bytes into Account values without knowing about CloudStore. Its test supplies CSV bytes directly and asserts the resulting collection, avoiding cloud mocks and setup.

How Data-Oriented Programming in Java covers it

How deep it goes
Derives boundaries from dependencies and demonstrates refactoring, but stops short of prescribing a complete application architecture.
Examples
Uses late-fee processing, invoice assessment, cloud CSV deserialization, and input-output tests as concrete applications.
What it assumes
Assumes familiarity with Java classes, tests, APIs, and dependency injection while making determinism boundaries concrete.
What you can do after
Build it from scratch by making environmental inputs explicit and isolating pure transformations for simpler tests.
How it connects
Connects determinism, pure functions, side effects, dependency boundaries, data-oriented design, and testing.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Data-Oriented Programming in Java. The section links point to the parts of the book it draws on.