示例#1
0
        /// <summary>
        /// The Interface factory approach is useful when your products need a simpler common framework.
        /// </summary>
        private static void ExecuteSimpleInterfaceExample()
        {
            Console.WriteLine("\n");
            Console.WriteLine("A Interface version of a factory Method Example.");
            // Createa some simple Factories
            InterfaceFactory.GameFactory gameFactory = new InterfaceFactory.GameFactory();

            // Create some mazes
            InterfaceFactory.IGame easyMaze = gameFactory.CreateGame("maze");
            InterfaceFactory.IGame easyCard = gameFactory.CreateGame("card");

            // Use the Announce Method
            easyMaze.Announce();
            easyCard.Announce();
        }
示例#2
0
        /// <summary>
        /// The Interface factory approach is useful when your products need a simpler common framework.
        /// </summary>
        private static void ExecuteSimpleInterfaceExample()
        {
            Console.WriteLine("\n");
            Console.WriteLine("A Interface version of a factory Method Example.");
            // Createa some simple Factories
            InterfaceFactory.IGameFactory easyGameFactory = new InterfaceFactory.EasyGameFactory();
            InterfaceFactory.IGameFactory hardGameFactory = new InterfaceFactory.HardGameFactory();

            // Create some games
            InterfaceFactory.IGame easyMaze = easyGameFactory.CreateGame("maze");
            InterfaceFactory.IGame hardMaze = hardGameFactory.CreateGame("maze");
            InterfaceFactory.IGame easyCard = easyGameFactory.CreateGame("card");
            InterfaceFactory.IGame hardCard = hardGameFactory.CreateGame("card");

            // Use the Announce Method
            easyMaze.AnnounceWinner();
            hardMaze.AnnounceWinner();
            easyCard.AnnounceWinner();
            hardCard.AnnounceWinner();
        }