かなり長い間私を悩ませてきた次の質問があります。次のドメインエンティティ「連絡先」をモデル化したいと思います:
public class Contact:IEntity<Contact>
{
private readonly ContactId _Id;
public ContactId Id
{
get { return this._Id; }
}
private CoreAddress _CoreAddress;
public CoreAddress CoreAddress
{
get { return this._CoreAddress; }
set
{
if (value == null)
throw new ArgumentNullException("CoreAddress");
this._CoreAddress = value;
}
}
private ExtendedAddress _ExtendedAddress;
public ExtendedAddress ExtendedAddress
{
get { return this._ExtendedAddress; }
set
{
if (value == null)
throw new ArgumentNullException("ExtendedAddress");
this._ExtendedAddress = value;
}
}
private readonly IList<ContactExchangeSubscription> _Subscriptions
= new List<ContactExchangeSubscription>();
public IEnumerable<ContactExchangeSubscription> Subscriptions
{
get { return this._Subscriptions; }
}
public Contact(ContactId Id, CoreAddress CoreAddress, ExtendedAddress ExtendedAddress)
{
Validations.Validate.NotNull(Id);
this._Id = Id;
this._CoreAddress = CoreAddress;
this._ExtendedAddress = ExtendedAddress;
}
}
ご覧のとおり、サブスクリプションのコレクションがあります。サブスクリプションは次のようにモデル化されます。
public class ContactExchangeSubscription
{
private ContactId _AssignedContact;
public ContactId AssignedContact
{
get { return this._AssignedContact; }
set
{
if (value == null)
throw new ArgumentNullException("AssignedContact");
this._AssignedContact = value;
}
}
private User _User;
public User User
{
get { return this._User; }
set
{
Validations.Validate.NotNull(value, "User");
this._User = value;
}
}
private ExchangeEntryId _EntryId;
public ExchangeEntryId EntryId
{
get { return this._EntryId; }
set
{
if (value == null)
throw new ArgumentNullException("EntryId");
this._EntryId = value;
}
}
public ContactExchangeSubscription(ContactId AssignedContact, User User, ExchangeEntryId EntryId)
{
this._AssignedContact = AssignedContact;
this._User = User;
this._EntryId = EntryId;
}
}
現在、自分のドメインでストレージ テクノロジ (Exchange) をモデル化するべきではないと考えています。結局、アプリケーションを他のサブスクリプション プロバイダーに切り替えたいと思うかもしれません。プロパティ「EntryId」は Exchange に固有です。ただし、サブスクリプションには常に User と ContactId が必要です。サブスクリプションをモデル化するより良い方法はありますか? 必要に応じて、サブスクリプション タイプにファクトリまたは抽象ファクトリを使用して、他のタイプのサブスクリプションをカバーする必要がありますか?
編集: それでは、リングに抽象ファクトリを投げて、いくつかのインターフェイスを紹介しましょう。
public interface IContactSubscriptionFactory
{
IContactSubscription Create();
}
public interface IContactSubscription
{
ContactId AssignedContact { get;}
User User { get; }
}
ContactExchangeSubscription の具体的なファクトリはどのようにコーディングされますか? このタイプには EntryID フィールドが必要であるため、追加の ctr パラメータを取得する必要があることに注意してください。一般に、工場のさまざまなサブタイプでさまざまなコンストラクターパラメーターを処理する方法は?