Ejemplo n.º 1
0
 public void Visit(Choice Choice)
 {
     foreach (ICostable costableItem in Choice.CostableItems)
     {
         costableItem.Accept(this);
         Choice.Cost += costableItem.Cost;
     }
 }
Ejemplo n.º 2
0
        static void Main(string[] args)
        {
            Recipe recipe = new Recipe();
            Choice chipsOrMash = new Choice();

            Product beans = new Product();
            Product sausages = new Product();
            Product chips = new Product();
            Product mash = new Product();

            recipe.CostableItems.Add(beans);
            recipe.CostableItems.Add(sausages);

            recipe.CostableItems.Add(chipsOrMash);
            chipsOrMash.CostableItems.Add(chips);
            chipsOrMash.CostableItems.Add(mash);

            Visitor visitor = new Visitor();
            recipe.Accept(visitor);

            Console.WriteLine(recipe.Cost);
        }