Optionality means that domain information may be present or absent, and that absence carries an explicit meaning. A nullable field hides this distinction; a deliberate model makes it visible and reviewable. section 2.6.3
Make optionality explicit rather than letting null silently bypass the model:
- Use a type representing either “something” or “nothing”; algebraically, the empty case has one value and the present case has the values of type A. section 4.6.4
- Treat fields that must always exist as invariants and reject nulls during construction when explicit protection is useful. section 2.6.3 section 9.3.1
- Refactor legacy models by identifying hidden optionality and encoding only the cases the domain actually permits. section 9.3.1
An optional seller identifier
A request can distinguish a missing seller identifier from an invalid required product identifier: `@NotBlank @NotNull String productId; Optional<String> sellerId;`. The type communicates that seller information is allowed to be absent, while validation keeps product identity mandatory. section 9.3.1
Combining optional values
Optional-aware operations can lift an ordinary binary operator into the Optional type. The same pattern combines optional policies, audit findings, and Boolean statuses while preserving the absent case. section 7.8.3
Figure 4.16 Sophisticated ideas can like optionality can be encoded as Product and Sum Types

See optionality represented directly through product and sum types. section 4.6.4
