Ejemplo n.º 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());
            }
            }
        }
Ejemplo n.º 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());
            }
            }
        }
        /// <summary>
        /// This constructor sets all public properties except for "Units".  This is intended to create the object before you know how many units are being consumed by the recipe.
        /// </summary>
        /// <param name="productName">The name of the Ingredient being used.</param>
        /// <param name="unitName">The unit of measure of the Ingredient being used.  It is assumed that this is the unit of measure for UnitCost and Units properties.</param>
        /// <param name="isOrganic">True if the item is organic, false otherwise.</param>
        /// <param name="unitCost">The price per unit as denoted by the UnitName parameter.  This is used in all Calculation functions.</param>
        /// <param name="ingredientType">The type of ingredient that exists in the closed list contained in enumIngredientType</param>
        public IngredientBaseItem(string productName, string unitName, bool isOrganic, double unitCost, enumIngredientType ingredientType)
        {
            Name      = productName;
            UnitName  = unitName;
            IsOrganic = isOrganic;

            UnitCost       = unitCost;
            IngredientType = ingredientType;
        }
 /// <summary>
 /// This constructor sets all public properties.  This is intended to create the object before you know how many units are being consumed by the recipe.
 /// </summary>
 /// <param name="productName">The name of the Ingredient being used.</param>
 /// <param name="unitName">The unit of measure of the Ingredient being used.  It is assumed that this is the unit of measure for UnitCost and Units properties.</param>
 /// <param name="isOrganic">True if the item is organic, false otherwise.</param>
 /// <param name="unitCost">The price per unit as denoted by the UnitName parameter.  This is used in all Calculation functions.</param>
 /// <param name="ingredientType">The type of ingredient that exists in the closed list contained in enumIngredientType</param>
 /// <param name="units">The number of units being consumed by the recipe.</param>
 public IngredientBaseItem(string productName, string unitName, bool isOrganic, double unitCost, enumIngredientType ingredientType, double units)
     : this(productName, unitName, isOrganic, unitCost, ingredientType)
 {
     Units = units;
 }