标签:des style blog io color ar sp for div
void Main() { (new Director()).Show(new VisitorA()); } class Director{ List<Element> elements = new List<Element>{ new ElementA(), new ElementB() }; public void Show(Visitor v){ foreach (var element in elements) { element.Show(v); } } } abstract class Element { public abstract void Show(Visitor v); } class ElementA:Element{ public override void Show(Visitor v){ v.ByEleA(this); } } class ElementB:Element{ public override void Show(Visitor v){ v.ByEleB(this); } } abstract class Visitor{ public abstract void ByEleA(ElementA ea); public abstract void ByEleB(ElementB eb); } class VisitorA:Visitor{ public override void ByEleA(ElementA ea){ "EA meet VA".Dump(); } public override void ByEleB(ElementB eb){ "EB meet VA".Dump(); } } class VisitorB:Visitor{ public override void ByEleA(ElementA ea){ "EA meet VB".Dump(); } public override void ByEleB(ElementB eb){ "EB meet VB".Dump(); } }
DesignPattern_Behavioral_Visitor
标签:des style blog io color ar sp for div
原文地址:http://www.cnblogs.com/rammderek/p/4103161.html