static void Main(string[] args) { //创建实体集 ObjectStructure structure = new ObjectStructure(); //添加男人和女人 structure.Attach(new Man()); structure.Attach(new Woman()); //实例化一个成功的访问者类型 Success success = new Success(); structure.Display(success); //实例化一个失败的访问者类型 Fail fail = new Fail(); structure.Display(fail); //实例化一个恋爱的访问者类型 Love love = new Love(); structure.Display(love); Console.ReadKey(); }
/// <summary> /// 访问者模式 /// </summary> /// <param name="args"></param> private static void Main(string[] args) { var o = new ObjectStructure(); o.Attach(new Man()); o.Attach(new Woman()); o.Display(new Success()); o.Display(new Failing()); o.Display(new Amativeness()); Console.Read(); }