I have a custom tree data class, following the standard Composite pattern. I obviously don't want the GUI and the model to be too closely tied, so the GUI should be an Observer of the model, and changes should be done through the model layer. I'm implementing observable support using C# events - so far, so good, and I have a working system.
- Which events would you expect an observable tree to generate? NodeCreate, NodeDelete, NodeMove?
- Would you create a single
TreeChange
event and encode change information in aTreeChangeEventArgs
, or would you create one event per update type (possibly along with specific EventArg classes for each)? NodeDeleting
orNodeDeleted
? Without getting the deleted Node as argument,NodeDeleted
seems of very limited use to me? Of course the tree could fire theNodeDeleted
event before (possibly) disposing the Node, but is it good practice throwing a (at least conceptually) deleted Node around?- When deleting a Node containing subnodes, would you expect getting a single
NodeDeleted
event, or recursiveNodeDeleted
for the subnodes as well? A singleNoteDeleted
seems fine to me, but perhaps there's some cases I haven't considered. - Changes of the individual nodes, as opposed to changes to the tree structure. I assume this is best handled by having the individual nodes observable? (I'm currently handling this with INotifyPropertyChanged on the node classes).
- No, I don't want to use a
Windows.Forms.TreeView
as my main data structure :)
And, the bonus question: let clients directly manipulate tree nodes and have the tree itself fire events, or do something along the lines of Service.Instance.AddNode(parentNode, "New node name")
and have the Service class responsible for generating events?