>>I have a graph of Leafs and Nodes.
>> A Node has 0...n Leafs
[quoted text clipped - 12 lines]
>
> contradict each other.
> >>I have a graph of Leafs and Nodes.
> >> A Node has 0...n Leafs
[quoted text clipped - 25 lines]
> --
> Mike W
So, your object graph itself is not immutable, but the nodes within it
may be? That doesn't quite make sense either.
In any case, isn't a Leaf just a type of Node? Often they are
implemented using the same class, as their behavior is the same.
Another common approach is a Node class and an Edge class.
visionset - 24 May 2007 22:20 GMT
>> So by modify an immutable I mean obtain an instance that reflects the new
>> state I require.
[quoted text clipped - 9 lines]
> So, your object graph itself is not immutable, but the nodes within it
> may be? That doesn't quite make sense either.
Item13: Always favour Immutability
> In any case, isn't a Leaf just a type of Node? Often they are
> implemented using the same class, as their behavior is the same.
> Another common approach is a Node class and an Edge class.
Yes I really mean Edge not Leaf (sorry for confusion)

Signature
Mike W
Lew - 25 May 2007 00:13 GMT
> Item13: Always favour Immutability
"Always favor" != "Always use"
You are supposed to think about the situation. Dogma is unreliable.

Signature
Lew
visionset - 26 May 2007 13:53 GMT
>> Item13: Always favour Immutability
>
> "Always favor" != "Always use"
>
> You are supposed to think about the situation. Dogma is unreliable.
You snipped the context, it was a response to the confusion of another
poster.
I don't think I've said 'always use'.

Signature
Mike W
Lew - 26 May 2007 15:37 GMT
>>> Item13: Always favour Immutability
>> "Always favor" != "Always use"
[quoted text clipped - 4 lines]
> poster.
> I don't think I've said 'always use'.
I wasn't trying to take issue with what you said but to point out for other
readers what the limitations are of such principles.

Signature
Lew
>>>I have a graph of Leafs and Nodes.
>>> A Node has 0...n Leafs
[quoted text clipped - 20 lines]
> I mean it really goes without saying, you can't Modify an Immutable,
> doesn't it?
This time, at least, it helped to say it.
But (and I'm not trying to be difficult, honestly) if you're going to
"modify" a leaf by making a new instance of it, the things that point to
leaves (i.e. Nodes) need to be mutable. Otherwise, when you change any
Leaf, you'll have to recreate the Nodes that point to it, and the leaves
that point to *them*, and the Nodes that point to *them*, ... in other words
the entire graph.
visionset - 24 May 2007 22:08 GMT
> But (and I'm not trying to be difficult, honestly) if you're going to
> "modify" a leaf by making a new instance of it, the things that point to
> leaves (i.e. Nodes) need to be mutable. Otherwise, when you change any
> Leaf, you'll have to recreate the Nodes that point to it, and the leaves
> that point to *them*, and the Nodes that point to *them*, ... in other
> words the entire graph.
Yes but most of the objects will be reused. Changing a Leaf will only cause
instantiation of that Leaf and its Nodes. Anyway expense isn't an issue,
code elegance and simplicity is the aim.
With that in mind, however, I think perhaps the best solution is Mutable
Nodes and Immutable Leafs.

Signature
Mike W