Implementing a Tree

Jan 8, 2009 at 9:43 AM
Hi,

Interesting thing for me is how to implement a tree with minimal code using Umrell.
I'm new to it but it seems should be fairly easy with Decorators and Observers.

The condition is to make this (meta)code working correctly:

var parent = new Node();
var child1 = new Node();
var child2 = new Node();

child1.Parent = parent;
Assert.IsTrue(parent.Children.Contains(child1));

parent.Children.Add(child2);
Assert.AreSame(parent, child2.Parent);

child2.Parent = child1;
Assert.IsTrue(child1.Children.Contains(child2));
Assert.IsFalse(parent.Children.Contains(child1))

child1.Parent = null;
Assert.IsTrue(parent.Children.Contains(child1));

child1.Children.Remove(child2);
Assert.IsNull(child2.Parent);


What are your ideas to do it with minimal code?

Cheers,
Dmitriy.