liveBook · Manning

Behavior

As explained in Data-Oriented Programming in Java

A behavior is a discrete computation or operation that changes a system from one state to another and produces outputs from inputs.

A behavior is a discrete computation or operation: it transforms one system state into another, taking inputs and producing outputs. This mechanical view applies even to actions that appear ephemeral, such as calling an API. section 5.3

Modeling behavior makes domain operations expressive, self-describing, and self-enforcing. Instead of allowing any invoice into a powerful method and defending against misuse at runtime, shape the operation so incorrect uses become impossible. section 5.2

Design behaviors by:

  • Identifying the states before and after an operation. section 5.3
  • Treating the requirements as machines that process one kind of data and produce another. section 5.3
  • Deciding how many transformations the domain needs before filling in implementation details. section 5.3

Late fees and billing

A late-fee process can be modeled as a machine: raw invoices enter, late-fee invoices leave. A generic submitBill(Invoice) operation, by contrast, permits the wrong invoice type and relies on cryptic checks for invoice type, identifiers, and audit information. section 5.2 section 5.3

Figure 5.9 Visualizing behaviors as a factory. Data in; Data out.

Visualizes behavior as a factory with data entering on one side and transformed data leaving on the other. section 5.3

How Data-Oriented Programming in Java covers it

How deep it goes
Defines behaviors as state transformations and sketches their design, while deferring implementation details.
Examples
Uses late-fee invoice processing, API calls, and a generic billing submission method as examples.
What it assumes
Assumes experience modeling data and deliberately postpones decisions about the contents of newly invented data types.
What you can do after
Build behaviors by identifying input and output states and separating domain transformations before implementation.
How it connects
Ties behaviors to data orientation, domain modeling, states, inputs, outputs, and APIs.

Also explained in

Compare how 6 books explain behavior →

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.