Click here to Skip to main content
15,893,622 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi there!

I need to find out effective solution about one detail in my project.

I have a tree of categories and artefacts(or products). Category can consists of other categories or products. How to organize business logic for these objects?

My solution is here:
<pre>public class CategoryBO
    {
        public int CategoryID { get; set; }
        public string Name { get; set; }
        public List<CategoryBO> Categories { get; set; }
        public List<ArtefactBO> Artefacts { get; set; }
    }




One my friend sugests me to use the property for parent:
<pre>public class CategoryBO
    {
        public int CategoryID { get; set; }
        public string Name { get; set; }
        public CategoryBO Parent { get; set; }
        public List<CategoryBO> Categories { get; set; }
        public List<ArtefactBO> Artefacts { get; set; }
    }




Which way is more effective or may be you know more flexible trick for this issue?
Posted

1 solution

The second one is more flexible since it gives the Parent Category from a category.In the first method , for finding the parent you have to do some iterations.If you have a requirement to find the parent category at any stage of your process the second one is much much better.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900