How do you model roles / relationships with Domain Driven Design?

If I have three objects: Project, ProjectRole and Person, where Person can be a member of different projects and be in different project roles (for example, "Project Lead" or "Project Member") - how would you model this relationship?

I currently have the following tabs in the database: Project, Person, ProjectRole Project_Person with PersonId and ProjectId as PK and ProjectRoleId as FK relation.

I'm really at a loss, because all the domain models that I came up with seem to violate the "DDD" rule. Are there "standards" for this problem?

I looked at optimized object modeling, and there is an example of what Project and ProjectMember will look like, but AddProjectMember () in Project will call ProjectMember.AddProject (). Thus, Project has a list of project participants, and each ProjectMember in the opposite direction refers to the project. It looks a bit confusing.

Update

After reading more about this subject, I will try the following: in my domain there are certain roles or, better, model relationships that have a certain type of role . For example, ProjectMember is a special role that tells us about the relationships that a person plays in the framework of the project. It contains ProjectMembershipType, which tells us more about the role it will play. I know for sure that people will have to play roles within the project, so I will model these relationships.

ProjectMembershipTypes can be created and modified. It can be "Project Manager", "Developer", "External Advisor" or something else.

, . ProjectMember.

public class ProjectMember : IRole
{
    public virtual int ProjectMemberId { get; set; }
    public virtual ProjectMembershipType ProjectMembershipType { get; set; }

    public virtual Person Person { get; set; }
    public virtual Project Project { get; set; }
    public virtual DateTime From { get; set; }
    public virtual DateTime Thru { get; set; }
    // etc...
}

ProjectMembershipType: .. " ", "", ""

public class ProjectMembershipType : IRoleType
{
    public virtual int ProjectMembershipTypeId { get; set; }
    public virtual string Name { get; set; }
    public virtual string Description { get; set; }

    // etc...
}
+5
5

"--": , , .

, Person ↔ Project RoleType / , RoleType , ( , "", FK , , /?)

- FK Person, Project Role, Project:

select a.person_id, b.project_role_id, c.project_id
from person a join project_role b on (a.id = b.person_id)
join project c on (b.project_id = c.id)
where a.person_id = ?

, Project:

select a.person_id, b.project_role_id, c.project_id
from person a join project_role b on (a.id = b.person_id)
join project c on (b.project_id = c.id)
where c.project_id = ?

#. , , , , , ProjectRole - .

, Project::addPerson( Person& ) Project::addProjectRole( ProjectRole& ), , Project::addPerson( Person& ) :

void Project::addPerson( Person& p ) {
  this.addProjectRole( new ProjectRole( p, &this, RoleType::UNASSIGNED ) ;
}

ProjectRole , . , RoleType ( , , ), , , , , ProjectRoles).

, Person , ; , , . , , ( ), . (NHibernate, , , .)

, , :

1) " "; 2) (, ) ; 3) , .

+1

:

class Person
{
  string Name { get; set; }
  IList<Role> Roles { get; private set; }
}

class Role
{
  string Name { get; set; }
  string Description { get; set; }
  IList<Person> Members { get; private set; }
}

class Project
{
  string Name { get; set; }
  string Description { get; set; }
  IList<ProjectMember> Members { get; private set; }
}

class ProjectMember
{
  Project Project { get; private set; }
  Person Person { get; set; }
  Role Role { get; set; }
}

ProjectMember . (, ProjectA ProjectB).

, , - .

, ( ):

  • "bin\debug\RolesRelationshipsSample.exe"
  • ,

. , .

+3

"" , ? "RoleDescription" ( " " ) "RoleInstance", , .

0

" " , . , , , . ProjectPerson, Person role:

public class ProjectPerson : Person
{
    public string Role { get; set; }
}

Project ProjectPerson, Person Project, Project . ( Person ProjectPerson), Person.

" " . ProjectRole " " Project Person. , ProjectRole.

, . , .

0

, - Project Project Member. " " " ". , .. , , . , - , /.

. Lookup , . , , - - " ".

I would not expect to see the essence or personality of Person in any business, except for convenience, as in the search table, as in the case above. Human resources departments will contain a list of employees who have certain information that is required for payroll, etc., but there is nothing fundamental to people whom the business should have known. NB Locate a business process to identify an entity - do not do this.

0
source

All Articles