private static void Feed(IEat eater, IFood food) { var soundMaker = eater as IMakeSounds; Console.WriteLine(); Console.WriteLine($"Trying to feed {food} (which belongs to the {food.FoodGroup} group, with a food value of {food.FoodValue}) to a {eater}"); Console.WriteLine($"Which is something it {(eater.CanEat(food) ? "can" : "cannot")} eat"); if (eater == food) { Console.WriteLine("Unfortunately it cannot eat itself"); return; } Console.WriteLine($"Currently the {eater} has a food level of {eater.FoodLevel}"); try { eater.Eat(food); Console.WriteLine($"The {eater} ate the {food}"); WriteSound(soundMaker, s => s.Contentment()); Console.WriteLine($"Now its food level is {eater.FoodLevel}"); } catch (Exception e) { WriteSound(soundMaker, s => s.Surprise()); Console.WriteLine(e); } }
static void Main(string[] args) { IWorker[] workers = new IWorker[3] { new Managers(), new Worker(), new Robot() }; foreach (var worker in workers) { worker.Work(); } IEat[] eat = new IEat[2] { new Managers(), new Worker() }; foreach (var eat in eats) { eat.Eat(); } }
public void Display() { eat.Eat(); }
public void Eat() { _eat.Eat(); }
public void Feed(IEat an) { Console.WriteLine($"{this.GetType().Name} is feeding {an.GetType().Name}"); an.Eat(); }
virtual public void WatchE(IEat an) { Console.Write($"{this.GetType().Name} is watching how "); an.Eat(); }
public void Eat(IEat eat) { eat.Eat(); }
public void Eat() { Ready(); // 喝前准备 m_eat.Eat(); // 开始喝水 EatDepth(); // 喝完反馈 }