【发布时间】:2012-05-06 16:43:52
【问题描述】:
我正在为配方应用程序开发域模型并遇到问题。
该应用程序具有多个能够充当成分的实体,其中两个是:Product 和 Recipe(配方可以是其他配方中的成分)。通常我会将与成分相关的功能封装到每个实体都可以实现的接口中。问题在于,虽然所有 Product 实例都可以是成分,但只有 Recipe 实例的一个子集可以是成分。
interface IIngredient
{
void DoIngredientStuff();
}
class Product : IIngredient
{
void DoIngredientStuff()
{
// all Products are ingredients - do ingredient stuff at will
}
}
class Recipe : IIngredient
{
public IEnumerable<IIngredient> Ingredients { get; set; }
void DoIngredientStuff()
{
// not all Recipes are ingredients - this might be an illegal call
}
}
如何重新构建此模型以支持只有一些配方实例才能充当成分的要求?
【问题讨论】:
-
要找出好的答案,我们需要了解为什么所有食谱都不能作为配料
标签: c# domain-driven-design data-modeling