Exemplo n.º 1
0
        public void Main()
        {
            var components = new List <IComponent>
            {
                new ConcreteComponentA(),
                new ConcreteComponentB()
            };

            Console.WriteLine("The client code works with all visitors via the base VisitorPattern interface:");
            var visitor1 = new XmlExportVisitor();

            Client.ClientCode(components, visitor1);

            Console.WriteLine();

            Console.WriteLine("It allows the same client code to work with different types of visitors:");
            var visitor2 = new PdfExportVisitor();

            Client.ClientCode(components, visitor2);
        }
Exemplo n.º 2
0
        private static void Visitor()
        {
            Book earth = new Encyclopedia();

            earth.name         = "Big Earth!";
            earth.author       = "Jose S. Massey";
            earth.categoryName = "Encyclopedia";

            Book daily = new Magazine();

            daily.name         = "Daily Magazine";
            daily.author       = "Wayne D. Eakin";
            daily.categoryName = "Magazine";


            IBookExportVisitor xmlExportVisitor  = new XmlExportVisitor();
            IBookExportVisitor jsonExportVisitor = new JsonExportVisitor();

            earth.Accept(xmlExportVisitor);
            daily.Accept(jsonExportVisitor);
        }