Many applications do not represent their data as a flat list but as a tree: an organization made of divisions and units, a mandator with sub-mandators, a documentation tree made of pages. For such trees, the module tl.element provides two base types a structure of your own derives from.
tl.element:StructuredElement is the base type of a node. It carries the reference parent to the node that contains it.
tl.element:StructuredElementContainer derives from StructuredElement itself and adds the reference children to the nodes it contains. A container is therefore always a node as well and can lie in another container, which is what makes the nesting possible.
Both references are abstract. They only state that there is a parent and a child relation, not which types may appear in them. That is exactly why every structure has to redeclare them.
A structure built on StructuredElement follows this scheme:
// Top-level type of the structure - each type of the structure extends it.
MyNode extends StructuredElement {
parent: MyContainer
}
// Abstract type for nodes with a substructure.
abstract MyContainer extends MyNode, StructuredElementContainer {
}
// Concrete types with children.
NodeA extends MyContainer {
children: ...
}
NodeB extends MyContainer {
children: ...
}
// Concrete type without children.
NodeC extends MyNode {
}
Three things about it matter:
parent and narrows the reference to the container type of its own structure. Every node thereby knows what kind of container it can lie in.children and narrows the reference to the types it may contain. Through this narrowing, the model controls what the user can create below a node.MyNode only, not from MyContainer. This is how leaves arise, below which nothing can be created.An abstract attribute cannot be accessed, neither for reading nor for writing. Without the redeclaration, every access to parent or children therefore fails with an error.
Earlier versions silently returned null in that case. A model that was missing the redeclaration appeared to work, but behaved inexplicably elsewhere. Since TopLogic 8.0 the error is reported directly, so that the inconsistency in the model becomes visible.