I am working on a domain model for a recipe application and am facing a problem.
The application has several objects that can act as an ingredient, two of which are: Productand Recipe(recipes can be ingredients in other recipes). I usually encapsulated the functionality associated with the ingredient in an interface that each of these objects could implement. The problem is that although all instances of a product can be ingredients , only a subset of instances of a recipe can be an ingredient .
interface IIngredient
{
void DoIngredientStuff();
}
class Product : IIngredient
{
void DoIngredientStuff()
{
}
}
class Recipe : IIngredient
{
public IEnumerable<IIngredient> Ingredients { get; set; }
void DoIngredientStuff()
{
}
}
How can I restructure this model to support the requirement that only certain instances of the Recipe act as an ingredient?