示例#1
0
        /// <summary>
        /// Returns an instance of a recipe item based on the type passed in, uses initializing constructor
        /// </summary>
        /// <param name="ingredientType">Type of ingredient you want to instanciate.</param>
        /// <param name="productName">Name of the ingredient.</param>
        /// <param name="unitName">Name of the units of measurement for the ingredient.</param>
        /// <param name="isOrganic">True if this item is organic, false otherwise.</param>
        /// <param name="unitCost">Cost per unit of this item.</param>
        /// <param name="units">Number of units of this ingredient in the recipe.</param>
        /// <returns>Instance of the item requested with properties initialized.</returns>
        public static IRecipeItem GetItemOfType(enumIngredientType ingredientType, string productName, string unitName, bool isOrganic, double unitCost, double units)
        {
            switch (ingredientType)
            {
            case enumIngredientType.Pantry:
            {
                return(new PantryItem(productName, unitName, isOrganic, unitCost, units));
            }

            case enumIngredientType.Produce:
            {
                return(new ProduceItem(productName, unitName, isOrganic, unitCost, units));
            }

            case enumIngredientType.MeatPoultry:
            {
                return(new MeatPoultryItem(productName, unitName, isOrganic, unitCost, units));
            }

            default:
            {
                throw new Exception("Unknown Ingredient type detected: " + ingredientType.ToString());
            }
            }
        }
示例#2
0
        /// <summary>
        /// Returns an instance of a recipe item based on the type passed in, uses default constructor
        /// </summary>
        /// <param name="ingredientType">Type of Ingredient you want to instanciate.</param>
        /// <returns>Instance of the item requested with properties left at default value</returns>
        public static IRecipeItem GetItemOfType(enumIngredientType ingredientType)
        {
            switch (ingredientType)
            {
            case enumIngredientType.Pantry:
            {
                return(new PantryItem());
            }

            case enumIngredientType.Produce:
            {
                return(new ProduceItem());
            }

            case enumIngredientType.MeatPoultry:
            {
                return(new MeatPoultryItem());
            }

            default:
            {
                throw new Exception("Unknown Ingredient type detected: " + ingredientType.ToString());
            }
            }
        }