【问题标题】:Domain object design for dynamic organization staff动态组织人员的领域对象设计
【发布时间】:2012-08-24 08:51:24
【问题描述】:

我有一个基本实体“组织”,它代表一个组织(无论是商业实体、棒球队还是播客)。很笼统。

这些组织中的每一个都可以有多个员工,每个员工可以是不同的类型。我们希望这是通用的和可变的,以便我们可以拥有一种或多种不同类型的员工(CEO、女服务员、教练、私人教练、经理、董事会成员)。有没有既定的方法来处理这个问题?

如果没有,我们将不胜感激任何对我的解决方案的反馈:

因此,我想通过组织中的“员工”成员来代表这一点。 Staff 将是“StaffMember”对象的集合,它们依次是:

StaffMember:
    person(a Person object)
    organization(an Organization object)(this may not be necessary if StaffMember is only used on an org)
    staffType

StaffType:
    title(string)
    significance(int)

这看起来可以吗?员工类型是我们可以根据需要创建的代表员工类型(主持人、首席执行官、首席财务官、董事会成员、教练等)的对象。因此,工作人员知道人员和类型。我们使用的是 MongoDB,因此“staff”属性可能是 StaffMembers 的嵌入式集合。

我只是想确保我没有忽略任何事情,所以任何反馈都将不胜感激!

【问题讨论】:

    标签: symfony doctrine-orm domain-driven-design symfony-2.1 doctrine-odm


    【解决方案1】:

    您应该考虑的一件事是组织中的预期员工人数。如果这个数字非常大,或者大于您在任何给定时刻希望在内存中拥有的数字,那么您可以考虑使用存储库而不是直接引用来实现此关联。这意味着组织类不会直接引用人员集合,而是必须使用存储库检索人员集合。请查看here 了解更多详情。

    此外,请注意双向关联,例如 StaffMember 和组织之间的关联。它们的建模成本低,但实施成本更高。基本上,尝试以不需要反向关系的方式设计系统。

    【讨论】:

      【解决方案2】:

      我们的产品有类似的结构。我们就是这样完成的。

      /** @MongoDB\Document(collection="companies") */
      class Company
      {
          // Properties
      
          /** @MongoDB\Id */
          protected $id;
      
          /** @MongoDB\String */
          protected $name;
      
          /** @MongoDB\ReferenceMany(targetDocument="Employee", mappedBy="company", cascade={"remove"}) */
          protected $employees;
      
          /** @MongoDB\ReferenceMany(targetDocument="Role", mappedBy="company", cascade={"remove"}) */
          protected $roles;
      }
      
      /**
       * @MongoDB\Document(collection="roles")
       * @MongoDB\UniqueIndex(keys={"title"="asc", "company"="asc"})
       */
      class Role
      {
      
          /** @MongoDB\Id */
          protected $id;
      
          /** @MongoDB\String */
          protected $title;
      
          /** @MongoDB\String */
          protected $description;
      
          /** @MongoDB\ReferenceMany(targetDocument="Employee", mappedBy="role") */
          protected $employees;
      
          /** @MongoDB\ReferenceOne(targetDocument="Company", inversedBy="roles") */
          protected $company;
      }
      
      /**
       * @MongoDB\Document
       * @MongoDB\DiscriminatorField(fieldName="type")
       * @MongoDB\DiscriminatorMap({"person"="Person", "employee"="Employee"})
       */
      class Employee extends Person
      {
          // Properties
      
          /** @MongoDB\String */
          protected $employeeId;
      
          /** @MongoDB\ReferenceOne(targetDocument="Role", inversedBy="employees") */
          protected $role;
      
          /** @MongoDB\ReferenceOne(targetDocument="Company", inversedBy="roles") */
          protected $company;
      }
      

      这允许公司内的大量员工担任大量角色。这很方便,因为您可以通过公司参考轻松获取角色/员工列表,而无需将详细信息存储在公司文档中。

      【讨论】:

        猜你喜欢
        • 2011-05-26
        • 2010-10-06
        • 1970-01-01
        • 2011-08-18
        • 2015-01-06
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2015-02-27
        相关资源
        最近更新 更多