liveBook · Manning

Attribute

As explained in Data-Oriented Programming in Java

An attribute is a named component of a data representation that describes one property of an entity or value.

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

How Data-Oriented Programming in Java covers it

How deep it goes
Explains attribute combinations as implicit ANDs and refactors conflicting combinations, but stops short of general attribute semantics.
Examples
Uses Status, Completed, Equals rules, invalid attribute-name strings, and an Attribute enum as concrete modeling examples.
What it assumes
Assumes Java record familiarity while teaching how to inspect fields as domain claims and recognize implicit AND relationships.
What you can do after
Evaluate data models for conflicting attribute combinations and constrain rule inputs with an enum.
How it connects
Connects attributes with records, algebraic data types, product types, sum types, enums, and business rules.

Also explained in

Compare how 32 books explain attribute →

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.