Hierarchical Data Implementation | Xafari Framework

Xafari framework provides a number of features for a comfortable and efficient work with hierarchical data. These features are available for objects that implement IHierarchyNode interface.

This post describes several ways to obtain hierarchical business objects:

  1. Implement IHierarchyNode interface from scratch, the result is XPO
  2. Inherit from DC.HierarchyNode, the result is Domain Component.
  3. Inherit from BC.DC.HierarchicalClassifierItem, the result is Domain Component.

1. HierarchyNodeObject class is BaseObject descendant and it implements IHierarchyNode interface:

As you can see from the code snippet above, HierarchyNodePersistentHelper class provides a ready-to-use method, thus allowing to implement IHierarchyNode interface very quickly and easily. Of course, if necessary, you can encode the methods of the interface on your own.

When implementing IHierarchyNode you must also declare Name, Parent and Children properties and decorate these with appropriate attributes: HierarchyNodeNamePropertyAttribute, ParentPropertyAtribute and ChildrenPropertyAttribute.

2. HierarchyNodeDescendant derived from Xafari.DC.HierarchyNode, it is Domain Component and it implements 4 different hierarchies.

Inheritance from PersistentDynamicObject eliminates the need to implement the logic of IList<HierarchyNodeDescendant> Children fields.

Children and Parent fields are defined for each hierarchy, HierarchyFullName field allows you to visualize the nesting.

When implementing multiple hierarchies, you must pass the hierarchy name as a parameter to the following attributes: HierarchyFullNamePropertyAttribute, ParentPropertyAttribute, ChildrenPropertyAttribute, HierarchyFullPathPropertyAttribute, HierarchyNodeNamePropertyAttribute.

Obtained Domain Component need to register in module:

3. HierarchicalClassifierItemDescendant Domain Component derived from Xafari.BC.DC.HierarchicalClassifierItem:

This implementation only requires the declaration of Parent and Children properties. To exclude the situation when node sets himself as a parent, the IsValidParent property has been declared. Thus it was possible to avoid infinite loops.

Complete sample project is available at HierarchyNode.

In case you have any other questions regarding hierarchical data implementation in Xafari Framework, just contact us.