私はDDDとエンティティおよび値型について学びました。エンティティタイプ内から値の型を設定する正しい方法を照会しています。以下の "Leader"クラスでは、 "SetAddress"と "SetName"メソッドがありますが、Entityタイプ内から値タイプを更新する正しい方法ですか?ドメイン駆動設計。エンティティタイプの設計
また、私はPhoneNumbersのリストを持っています、これを処理するための推奨される方法は何ですか?私はリストにあなたの助けのためのEG-
leader.PhoneNumbers.Add(new PhoneNumber("12345", Mobile);
感謝のPhoneNumberを追加する必要があります:
public class Leader:Entity
{
public void SetName(string firstName, string surname)
{
Name = new Name(firstName, surname);
}
public Name Name { get; private set; } = Name.Empty;
public void SetAddress(string street, string city, string postode)
{
Address = new AddressDetails(street, city, postode);
}
public AddressDetails Address { get; private set; } = AddressDetails.Empty;
public List<Phone> PhoneNumbers { get; set; }
}
public class AddressDetails : ValueObject<AddressDetails>
{
public static readonly AddressDetails Empty = new AddressDetails(string.Empty, string.Empty, string.Empty);
public AddressDetails(string street, string city, string postode)
{
Street = street;
City = city;
Postcode = postode;
}
public string Street { get; }
public string City { get; }
public string Postcode { get; }
protected override bool EqualsCore(AddressDetails other)
{
return Street == other.Street &&
City == other.City &&
Postcode == other.Postcode;
}
protected override int GetHashCodeCore()
{
unchecked
{
int hash = 17;
hash = (hash * 23)^Street.GetHashCode();
hash = (hash * 23)^City.GetHashCode();
hash = (hash * 23)^Postcode.GetHashCode();
return hash;
}
}
}
ありがとうございました。それはすべて意味をなさない。電話番号のリストを処理するために、 "PhoneList"または "PhoneCollection"タイプが必要なような気がします。 – Andrew