Friday, 15 June 2012

c# - Should i have Parent or ListOfChild property in Hierarcical object -



c# - Should i have Parent or ListOfChild property in Hierarcical object -

i have uncertainty on how model hierarchical object storing tag tree:

thinking db table can use

public class tag { public int id { get; set; } public int description { get; set; } private readonly tag parenttag; public tag parenttag { { homecoming parenttag; } } }

the code parent property come hierarchical object , autofixture avoid circular reference

but suggested there, , thinking object maybe improve having kid collection instead of parent: naturally speaking tag can have collection of kid tags create more sense class become:

public class tag { public int id { get; set; } public int description { get; set; } private ilist<tag> childtag; public ienumerable<tag> childtag { { homecoming childtag.remove(0); } } }

but in way how can move tag in tree: alter parent property on tag?

edit

thinking object have say:

create new root create new child move node say if node child say if node root get kid of node (recursivly) delete kid (recursivly , not)

i have allow user create trees of tags tagging documents stored accomplish similar tag collection used lightroom pictures

whether have parent property on child, or children property on parents, should depend on code needs do.

try this: remove both properties , see if cares.

responding update. utilize test-driven development whenever possible. tests become executable definition of "what programme need do" (a: needs pass tests). process of making tests pass forces implement code in simplest way possible still passes tests.

you can same thing without tdd first writing set of client code calls class, implementing what's required in order client code work. recommend remove both properties in question, start writing code. determine whether or not need one, or both, properties.

c# domain-driven-design hierarchy

No comments:

Post a Comment