コード例 #1
0
        public static IPizza CreateRandomPizza()
        {
            Random rn    = new Random();
            IPizza pizza = new PlainPizza(rn.Next(20, 100));

            if (rn.Next(2) == 1)
            {
                pizza = new ExtraCheeseTopping(pizza);
            }
            else if (rn.Next(2) == 1)
            {
                pizza = new JalapenoTopping(pizza);
            }
            else if (rn.Next(2) == 1)
            {
                pizza = new MushroomTopping(pizza);
            }

            return(pizza);
        }
コード例 #2
0
        static void Main(string[] args)
        {
            var pizza = new Margherita();

            Console.WriteLine("Plain Margherita: " + pizza.GetPrice().ToString());

            var moreCheese     = new ExtraCheeseTopping(pizza);
            var someMoreCheese = new ExtraCheeseTopping(moreCheese);

            Console.WriteLine("Plain Margherita with double extra cheese: " + someMoreCheese.GetPrice().ToString());

            var moreMushroom = new MushroomTopping(someMoreCheese);

            Console.WriteLine("Plain Margherita with double extra cheese with mushroom: " + moreMushroom.GetPrice().ToString());

            var moreJalapeno = new JalapenoTopping(moreMushroom);

            Console.WriteLine("Plain Margherita with double extra cheese with mushroom with Jalapeno: " + moreJalapeno.GetPrice().ToString());

            Console.ReadLine();
        }