如果一个对象具有Single Responsibility,是否可以接受以下内容:
public class Person
{
public string Name;
public DateTime DateOfBirth;
private IStorageService _storageService;
public Person(IStorageService storageService)
{
_storageService = storageService
}
public void Save()
{
_storageService.Persist(this);
}
}
即使用提供的合作者(这也有助于阻止域模型贫血)。
或者应该是:
public class Person
{
public string Name;
public DateTime DateOfBirth;
public Person()
{
}
}
public class StorageService
{
public void Persist(Person p)
{
}
}