The Composite: The Recursive Fractal Nodes
Compose objects into tree structures to represent part-whole hierarchies.
✧ GANG OF FOUR LINEAGE & ARCANUM ✧
GOF DESIGN PATTERN: Composite
ARCANUM SCHOOL: Illusion // Fractal-Weaving
SCRIBE / ARCHON: JoshuaালোEdward McLaughlin Cox
CANONICAL REGISTRATION:
// ALLOY PATTERN //
abstract sig FractalNode {}
sig SingularNode extends FractalNode {}
sig ClusterNode extends FractalNode {
children: set FractalNode
}
fact "The Fractals Shall Not Loop" {
no c: ClusterNode | c in c.^children
}
pred valid_tree {
some ClusterNode
}
run valid_tree for 5
The Composite: The Recursive Fractal Nodes
The essence of the Composite pattern lies in tree structures. In Alloy, we allow ClusterNode to contain a set of FractalNode elements, which might be clusters themselves. The critical incantation is the fact The Fractals Shall Not Loop—utilizing the transitive closure operator ^ to forbid circular containment, keeping reality intact.
Runic Tags:
#structural
#composite
#trees