Пример #1
0
        static MoneyAmount Reserve(MoneyAmount cost)
        {
            decimal factor = 1;

            if (IsHappyHour)
            {
                factor = 0.5M;
            }
            Console.WriteLine("\nReserving an item that cost: {0}.", cost);
            return(cost.Scale(factor));
        }
Пример #2
0
        // Reference types are susceptible to aliasing bugs;
        // By changing contents of an existing object we are risking an aliasing bug to apear;
        // Try to avoid instantiating objects directly;
        // Modification to the constructor requires update in all consumers;
        // Let objects of the class construct subsequent objects;
        private static MoneyAmount Reserve(MoneyAmount cost)
        {
            decimal factor  = 1;
            var     newCost = cost;

            if (IsHappyHour)
            {
                // Create new object when content should change;
                factor = .5M;
            }

            Console.WriteLine($"\nReserving an item that costs {cost}");
            return(cost.Scale(factor));
        }