In many projects I was faced with storing hierarchical data (tree) in classes.
By tree, I mean such data, where each node has a parent node — an object of the same class.
Many examples of such data can be given. For example, a catalog in the online store. Suppose that this online store sells books, in this case, the category tree might look like this:
The number in front of the name is the category ID.
For storage, you can create classes:
The MyApp.Category class is used to store the category tree and contains the property “Parent” - reference to the same class.



