A common question I’ve seen from beginners is whether it’s better to make a parent relation or a set of child relations, like so:
-- which field is better?
sig Parent {
children: set Child
}
sig Child {
parent: Parent
}
First of all, a common beginner mistake is people thinking they need both. Since any relation is invertible with ~
, you only need one: parent = ~children
and vice versa. In fact having one is preferable, since you don’t need to add a fact to keep them in sync.
So the choice should instead depend on structural concerns. Each creates a different set of possible models. With set children
, it’s possible for multiple Parents to share a Child. It’s also possible for a Child to not have any Parents. With parent
, you guarantee that every Child has exactly one Parent.
I generally find that using parent
or lone parent
is preferable unless my domain explicitly permits having multiple Parents share children.