Our current O/RM tool does not really allow for rich domain models, so we are forced to utilize anemic (DTO) entities everywhere. This has worked fine, but I continue to st
If your ORM technology only handles DTO objects well, that doesn't mean you have to throw out rich entity objects. You can still wrap your DTO objects with entity objects:
public class MonkeyData
{
public string Name { get; set; }
public List FavoriteFood { get; set; }
}
public interface IMonkeyRepository
{
Monkey GetMonkey(string name) // fetches DTO, uses entity constructor
void SaveMonkey(Monkey monkey) // uses entity GetData(), stores DTO
}
public class Monkey
{
private readonly MonkeyData monkeyData;
public Monkey(MonkeyData monkeyData)
{
this.monkeyData = monkeyData;
}
public Name { get { return this.monkeyData.Name; } }
public bool IsYummy(Food food)
{
return this.monkeyData.FavoriteFood.Contains(food);
}
public MonkeyData GetData()
{
// CLONE the DTO here to avoid giving write access to the
// entity innards without business rule enforcement
return CloneData(this.monkeyData);
}
}