V
visionset
I have a graph of Leafs and Nodes.
A Node has 0...n Leafs
A Leaf has 1...2 Nodes.
The referencing is circular.
During execution I wish to modify both Nodes (eg add/remove Leafs) and Leafs
(eg add a Node to a single Noded Leaf).
The Leaf is easy to make Immutable, but does it make sense to make the Node
immutable?
Since my model holds a collection of references to all the nodes[1], the
collection itself, is mutable so I can swap nodes in and out if I were to
have an immutable Node. The overhead of recreating Nodes and linking them
is not going to be a problem. Really my concern is the simplicty of the
code. On one hand immutables themselves are simple and have the usual
advantages but on the downside there will be more code that has to
reestablish the natural composition references that would otherwise (with a
mutable) already exist.
If I end up having a mixture of Mutable Node and Immutable Leaf, then I'll
have Sets of Leafs and Lists of Nodes, since I see it non-sensical (and
error prone) to have a Set of mutables. But I guess that doesn't matter.
[1] I don't rely on traverseing the graph because there are non-contiguous
graph portions.
TIA,
A Node has 0...n Leafs
A Leaf has 1...2 Nodes.
The referencing is circular.
During execution I wish to modify both Nodes (eg add/remove Leafs) and Leafs
(eg add a Node to a single Noded Leaf).
The Leaf is easy to make Immutable, but does it make sense to make the Node
immutable?
Since my model holds a collection of references to all the nodes[1], the
collection itself, is mutable so I can swap nodes in and out if I were to
have an immutable Node. The overhead of recreating Nodes and linking them
is not going to be a problem. Really my concern is the simplicty of the
code. On one hand immutables themselves are simple and have the usual
advantages but on the downside there will be more code that has to
reestablish the natural composition references that would otherwise (with a
mutable) already exist.
If I end up having a mixture of Mutable Node and Immutable Leaf, then I'll
have Sets of Leafs and Lists of Nodes, since I see it non-sensical (and
error prone) to have a Set of mutables. But I guess that doesn't matter.
[1] I don't rely on traverseing the graph because there are non-contiguous
graph portions.
TIA,