liveBook · Manning

Containment

As explained in Building User-Friendly DSLs

A directed relation expressing that a source object contains and owns a target object, with at most one incoming containment relation per target.

Containment is a directed ownership relation from a source object to a target object. A solid arrow labeled with a property name shows that the source contains the target through that property. A target may have at most one incoming containment relation, and an object cannot contain itself. section 2.1

Treat a containment relation as a non-simple setting on its source: the property label is the setting name and the target object is its value. This restriction makes containment suitable for tree-like structure; use a dashed reference relation when an object must point to another object without owning it. section 2.1 section 2.2

Containing record attributes

A Record Type named Rental contains its Data Attribute objects through an attributes property. Each attribute can in turn contain an initial value object, such as a Number. The nested ownership mirrors the visible structure of the record definition. section 2.2

Figure 2.12 Connecting the attributes objects to the Record Type object through containment relations
figure

This diagram shows the Rental record object connected to its attribute objects through the multivalued attributes containment property. section 2.2

In a JavaScript AST encoding, represent each contained object as a separate object and place it in the containing property’s value. A multivalued containment property uses an array, so Rental’s attributes setting holds the attribute objects; nested initial value settings hold their own contained objects. section 3.1.1 section 3.2.1

Accessing a contained object

Access the fourth contained attribute with rental.settings["attributes"][3]. The attributes setting evaluates to an array, and JavaScript array indexes start at 0, so index 3 selects position four. section 3.2.1

How Building User-Friendly DSLs covers it

How deep it goes
Defines ownership constraints, contrasts references, and works through JavaScript encoding and array-based access.
Examples
Uses a Rental Record Type containing four Data Attribute objects and nested Number initial values.
What it assumes
Introduces JavaScript object and array access while explaining zero-indexed array positions.
What you can do after
Apply it via JavaScript objects and arrays to encode and access owned AST objects.
How it connects
Connects containment to object-relation diagrams, settings, reference relations, abstract syntax trees, and JavaScript arrays.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Building User-Friendly DSLs. The section links point to the parts of the book it draws on.