G
G
gadpaw2015-05-12 12:03:33
C++ / C#
gadpaw, 2015-05-12 12:03:33

How to represent the hierarchy of elements?

What is the best way to represent a set of objects (of different types) that
are nested inside each other? Can move to a higher level of the hierarchy, collapse
by certain properties, filter ...

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
Stanislav Makarov, 2015-05-12
@gadpaw

class Obj { }
class Collection : Obj
{
   private List<Obj> items;
}
class Item : Obj { }

the pattern is called Linker. You can start with Wikipedia .

V
Vitaly Pukhov, 2015-05-12
@Neuroware

it is not entirely clear what is meant by "different types", usually a hierarchy of elements is not built from anything, the simplest case is a class of the form

class Item{
public Item Parent;
public Object Data;
public List<Item> Childs;
}

Accordingly, Parent stores information about the parent, Data "any type", and Childs, respectively, the list of children

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question