- 給定一個
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