- 给定一个
Employee
实体和一堆个人/组织的相关信息(如婚姻状况,儿童的信息,部门,位置)。是否所有个人信息都被表示为组件/值对象,或者信息更好地驻留在实体类中?使用 会的人(这可以收集所有的个人信息)值对象为基本对象(
composition
)为Employee
实体是一个糟糕的设计选择?合适的领域模型设计此外,如何正确建模这样的行为(根据
DDD
):If employee has kids then it should have a birth certificate (with corresponding data: name, issue date, etc)
或If employee is married then it should have marriage certificate (with corresponding data: spouse name, etc)
?
对于一个孩子的情况下,我决定使用ChildrenInformation
值对象:
public class ChildrenInformation
{
public String BirthCertificateCode { get;set; }
public DateTime BirthCertificateIssueDate { get;set; }
public ChildName { get; set; }
public ChildMiddleName { get; set; }
public ChildLastName { get; set; }
public DateTime ChildBirthday{ get; set; }
}
public class Employee : AbstractEntity<Employee>, IAggregateRoot
{
public ISet<ChildrenInformation> ChildrenInformation { get; set; }
/* other things ...*/
}
岂不是从设计的观点错了吗?
编辑
另一种认为是分享Certificate
类。
[Serializable]
public class Certificate
{
public String Code { get; set; }
public String Number { get; set; }
public String RegistreeName { get; set; }
public Address RegistreeAddress { get; set; }
public String RegistreeDateOfBirth { get; set; }
public String RegistredAt { get; set; }
public DateTime DateRegistred { get; set; }
}
[Serializable]
public class Employee : AbstractEntity<Employee>, IAggregateRoot
{
public Certificate Passport { get; set; }
public Certificate MarriageCertificate { get; set; }
public ISet<Certificate> ChildrenBirthCertificates { get; set; }
}
谢谢!
普通法婚姻怎么样?他们可能没有结婚证书,但他们的“婚姻”仍然可以作为国内合作伙伴。 – 2012-01-13 15:23:49
@MarkKram国内关系不在这里考虑。 – lexeme 2012-01-16 06:45:21