Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/oop/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/83.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 在组织中代表成员的最佳实践_C#_Oop_Modeling - Fatal编程技术网

C# 在组织中代表成员的最佳实践

C# 在组织中代表成员的最佳实践,c#,oop,modeling,C#,Oop,Modeling,用面向对象的方法表示组织成员的最佳实践是什么。是否最好将成员作为集合存储在组织模型中,如下所示: public class Organisation { public Guid Id { get; set; } public ICollection<Person> Members { get; set; } // the rest of the code } 公共类组织 { 公共Guid Id{get;set;} 公共ICollection成员{get;

用面向对象的方法表示组织成员的最佳实践是什么。是否最好将成员作为集合存储在组织模型中,如下所示:

public class Organisation
{
    public Guid Id { get; set; }

    public ICollection<Person> Members { get; set; }

    // the rest of the code
}
公共类组织
{
公共Guid Id{get;set;}
公共ICollection成员{get;set;}
//代码的其余部分
}
或者最好不要将它们存储在组织内部,而是在Person类中引用组织,如下所示:

public class Organisation
{
    public Guid Id { get; set; }

    // the rest of the code
}

public class Person
{
    public ICollection<Organisation> OrganisationMemberships { get; set; }

    // the rest of the code
}
公共类组织
{
公共Guid Id{get;set;}
//代码的其余部分
}
公共阶层人士
{
公共ICollection组织成员身份{get;set;}
//代码的其余部分
}
说到一种将两者紧密联系在一起的方法,这意味着该计划不仅会呈现一个组织或一个人,还会呈现来自两者的信息片段。 比如说,一家公司的部门领导人数,包括公司名称和员工总数。 此外,该模型还针对关联组织,与军事单位和/或子公司的结构非常相似


这两种方法对性能的影响是什么?是一种方式明显优于另一种方式,还是归结于个人偏好?

由于这是N:M关系,它通常归结于实现细节。。。比如谁真正需要这个参考资料


两边都有的主要缺点是保持一致性——当你向一个组织添加/删除人员时,你还需要确保另一个链接也被添加/删除。

对我来说,这听起来像是个人偏好。但是,人与组织之间的关系是什么?是否允许一个人加入多个组织?如果不是这样的话,那么在组织类中使用Person集合作为成员将是最好的选择。经验法则是保持简单:当你不打算使用参考文献时,不要包含太多参考文献。为什么会有这样的最佳实践?同意!当应用程序大规模运行时,维护一致性是一件令人头疼的事情。