A heterogeneous string map is a map whose string-keyed values can have different types or shapes. In data-oriented programming (DOP), it represents a record: field names and value types are not fixed in a class. That trade-off gives data flexibility and genericity while reducing compile-time safety. section 3.2 section 3.6
Keep the two map roles distinct:
- Use a heterogeneous map for a record with known field names and values of different shapes, such as an ISBN, title, year, author identifiers, and book items. section 12.1
- Use a homogeneous map for an index with unknown field names and values sharing a common shape, such as booksByIsbn or authorsById. section 12.1
- Access nested information through paths and generic functions; this keeps code weakly dependent on the data representation and makes field changes easier to absorb. section 3.6
A library record without a Book class
A Watchmen record can combine strings, a number, an array of author identifiers, and an array of nested book-item maps. The same shape can be written as a generic map in JavaScript or Java, rather than instantiated through Book and BookItem classes.
Listing 3.1 An instance of a Book record represented as a map
{
"isbn": "978-1779501127",
"title": "Watchmen",
"publicationYear": 1987,
"authors": ["alan-moore", "dave-gibbons"],
"bookItems": [
{
"id": "book-item-1",
"libId": "nyc-central-lib",
"isLent": true
},
{
"id": "book-item-2",
"libId": "nyc-central-lib",
"isLent": false
}
]
}
Inspect the complete nested record to see how primitive values, positional collections, and nested maps compose one heterogeneous structure. section 3.2
