Basically each entity would have a collection of feeding behaviors that it would follow. For some reason the model I came up with does not feel right. I think the most troubling part is that using singletons made sense.
Is there a better way?
public bool IsEntityEdible(Entity target)
{
foreach (var feedingBehavior in FeedingBehaviors)
{
if (feedingBehavior.WouldEat(target))
{
return true;
}
}
return false;
}
public abstract class FeedingBehavior
{
public abstract bool WouldEat(Entity entity);
}
public sealed class Myrmecophagy : FeedingBehavior
{
public readonly static Myrmecophagy Instance = new Myrmecophagy();
private Myrmecophagy() { }
public override bool WouldEat(Entity entity)
{
return entity is Ant || entity is Termite;
}
}