到域驅動的開發專家那裏...這是域驅動設計嗎?
我想要真正把握DDD的概念。到目前爲止,我一直在設計我的模型是數據驅動的而不是域驅動的。我已經閱讀了幾篇有關DDD的文章,並且看起來非常有趣,特別是對於大型應用程序。所以我正在試圖調整我的模型來做到這一點。
我不得不說,暴露出這將禁用所有客戶賬戶的方法FreezeAccounts客戶實體。此方法不涉及數據訪問(基於持久性忽略規則)。它更新每個客戶帳戶(按需加載)上的標誌並將更改保存到數據庫。這是正確的基於這種模式?我已經讀過,在DDD中,每個表實體不一定只有一個類。這個功能應該在一個單獨的類中嗎?下面是一些示例代碼:
public class Customer : ICustomer, ICustomerAction
{
#region Initialization
public Customer()
{
}
internal Customer(ICustomer view)
{
this.CustomerId = view.CustomerId;
this.Name = view.Name;
this.Email = view.Email;
this.IsActive = view.IsActive;
}
#endregion
#region Instances
private AccountCollection _accounts;
#endregion
#region Properties
#region ICustomer
public int CustomerId { get; private set; }
public string Name { get; set; }
public string Email { get; set; }
#endregion
#region Derived
public AccountCollection Accounts
{
get
{
if (_accounts == null)
_accounts = Account.GetListByCustomerId(CustomerId);
return _accounts;
}
}
#endregion
#endregion
#region Methods
#region CRUD
// Data Access Object accepts interface ICustomer
internal void Update()
{
CustomerDb.Update(this);
}
#endregion
#region ICustomerAction
// Exposed business Persistence Ignorance action
internal void FreezeAccounts()
{
foreach (Account account in this.Accounts)
{
account.IsEnabled = false;
account.Update();
}
}
#endregion
#endregion
}
現在一切都很清楚。我的例子是遵循傳統的活動記錄模式,而不是DDD。業務對象正在與存儲庫進行交互,而不是使應用程序服務與存儲庫和域(服務/實體)交互。關鍵詞:工作單元,實體根源和服務幫助清除圖像。謝謝! – fips
那你爲什麼不接受正確的答案? :-) – inf3rno