首先我的要求是
“我们可以创建一个账户并在上面存钱,当我们购买一件物品时,我们会减少账户”
所以我的 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
它只是假设处理数据存储。