你好! 我需要找到有关我项目中一个细节的有效解决方案. 我有一棵类别和人工制品(或产品)的树.类别可以包含其他类别或产品.如何组织这些对象的业务逻辑? 我的解决方案在这里:
<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; } }我的一个朋友建议我将其财产用作父母:
<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; } }解决方案
第二种方法更灵活,因为它从类别中提供了父类别.在第一种方法中,要查找父类,您必须进行一些迭代.如果需要在过程的任何阶段找到父类,则第二种要好得多.
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?
解决方案 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.