Should I have a Parent or ListOfChild property in a Hierarcical object

I have doubts about how to model a hierarchical object to store a tag tree:

thinking in db table i can use

public class Tag
{
    public int Id { get; set; }
    public int Description { get; set; }
    private readonly Tag parentTag;
    public Tag ParentTag
    {
        get
        {
            return parentTag;
        }
    }
}

the code from the parent property comes from the Hierarchical object and AutoFixture to avoid circular reference

but, as was suggested there, and to think about making the object perhaps better to have a child collection instead of a parent: naturally, a tag can have a set of child tags that are more reasonable So, my class has become:

public class Tag
{
    public int Id { get; set; }
    public int Description { get; set; }
    private IList<Tag> childTag;
    public IEnumerable<Tag> ChildTag
    {
        get
        {
            return childTag.remove(0);
        }
    }
}

but in this way, how can I move the tag in the tree: is it a change in the parent property in my tag?

EDIT

thinking about what my object should do, I would say:

  • create a new root
  • create a new child
  • move node
  • , node
  • , node
  • node ()
  • ( )

, , Lightroom

0
1

Parent Children , , .

: , .


. . " " (A: ). , .

TDD, , , , , . , , . , .

0

Source: https://habr.com/ru/post/1545340/


All Articles