An attribute is a named component of a data representation that describes one property of an entity or value. In a Java record, each attribute contributes to the meaning of the represented data. section 4.2.1 section 4.9
Attributes combine through an implicit AND: every field says that the represented value has that property. This makes their combination a design test. Instance and Step can describe a general Status, while completedBy and completedOn point toward a distinct Completed type. section 4.2.1 section 4.9
Use attributes deliberately when modeling data:
- Read the record as the compiler does rather than relying on explanatory prose. section 4.2.1
- Check whether every combination of attributes describes a coherent value. section 4.2.1
- Move contextual attributes into a more specific data type when they change the meaning of the whole representation. section 4.2.1
- Replace open-ended attribute names with an enum when only a fixed set of attributes is valid. section 8.3
From an open string to a constrained attribute
A rule such as new Equals("country", "US") stores the selected attribute as a string, allowing misspellings such as "county". Replacing the name with Attribute.COUNTRY restricts the rule to attributes represented by the enum. section 8.3































