【发布时间】:2011-12-20 17:09:07
【问题描述】:
首先我的要求是
“我们可以创建一个账户并在上面存钱,当我们购买物品时,我们会减少账户”
所以我的 AccountController 看起来像
class AccountController
{
private IAccountDataSource _accountDataSource;
Create(Account anAccount)
{
_accountDataSource.Insert(anAccount);
Render(anAccount.Id);
}
}
但是有一个新的要求 "有些人可以拥有一个免费帐户(所有项目都是免费的),但如果我们创建一个真实帐户,我们就会删除该免费帐户"
所以我的 controller.Create 变成了
Create(Account anAccount)
{
_accountDataSource.Insert(anAccount);
RemoveFreeAccount(anAccount.Customer);
Render(anAccount.Id);
}
RemoveFreeAccount(Customer aCustomer)
{
_accountDataSource.Remove(new AccountFilter() { Type='Free', CustomerId=aCustomer.Id });
}
但对我来说,我觉得我应该把这个 RemoveFreeAccount 放在其他地方,但我不知道在哪里,因为 IAccountDataSource 只是假设处理数据存储。
【问题讨论】:
标签: design-patterns solid-principles