예제 #1
0
파일: Visitor.cs 프로젝트: RocGod/brianrepo
 public void Visit(Recipe recipe)
 {
     foreach (ICostable costableItem in recipe.CostableItems)
     {
         costableItem.Accept(this);
         recipe.Cost += costableItem.Cost;
     }
 }
예제 #2
0
파일: Program.cs 프로젝트: RocGod/brianrepo
        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);
        }