private static void SimpleObserverTest() { Console.WriteLine("简单实现的观察者模式:"); Console.WriteLine("===================="); //Init rob var fishingRod = new FishingRod(); //Init fishman var sifan = new FishingMan("思凡"); //fishman observe rob fishingRod.AddSubcriber(sifan); while (sifan.FishCount < 5) { fishingRod.Fishing(); Console.WriteLine("------------------"); Thread.Sleep(5000); } }
/// <summary> /// 测试简单实现的观察者模式 /// </summary> private static void SimpleObserverTest() { Console.WriteLine("简单实现的观察者模式:"); Console.WriteLine("======================="); //1、初始化鱼竿 var fishingRod = new FishingRod(); //2、声明垂钓者 var jeff = new FishingMan("圣杰"); //3、将垂钓者观察鱼竿 fishingRod.AddSubscriber(jeff); //4、循环钓鱼 while (jeff.FishCount < 5) { fishingRod.Fishing(); Console.WriteLine("-------------------"); //睡眠5s Thread.Sleep(5000); } }