Пример #1
0
 static void Main(string[] args)
 {
     //AbstractFactoryPattern.Run();
     //BuilderPattern.Run();
     //FactoryMethodPattern.Run();
     AdapterPattern.Run();
 }
Пример #2
0
        static void Main(string[] args)
        {
            Console.WriteLine("Decorator Example");
            DecoratorPattern.DecoratorExample();
            Console.WriteLine("Decorator Example Finished");

            Console.WriteLine("----------------------------------------------------------");

            Console.WriteLine("Adapter Example");
            AdapterPattern.AdapterExample();
            Console.WriteLine("Adapter Example Finished");



            Console.WriteLine("Factory Example");
            EmployeeFactory EmployeeFactory = new ConcreteEmployeeFactory();

            IFactory permanentEmployee = EmployeeFactory.Factory("PermanentEmployee");

            permanentEmployee.details();

            IFactory TemporaryEmployee = EmployeeFactory.Factory("TemporaryEmployee");

            TemporaryEmployee.details();
            Console.WriteLine("Factory Example Finished");
            Console.Read();
        }
Пример #3
0
        static void Main(string[] args)
        {
            #region Patterns
            //factory patterns
            RunSimpleFactory();
            RunAbstrctMethodFactory();

            //Singleton pattern
            RunSingleton();
            #endregion

            #region StructVSClass
            //Struct vs Class

            TestStruct testStruct = new TestStruct();
            TestClass  testClass  = new TestClass();

            testStruct.x = 1;
            testClass.x  = 1;

            StructTest.TakeClass(testClass);
            StructTest.TakeStruct(testStruct);

            Console.WriteLine();
            Console.WriteLine("TestClass = {0} TestStruct = {1}", testClass.x, testStruct.x);
            #endregion

            #region index test
            //indexer test
            MyArray myTestArray = new MyArray();

            for (int i = 0; i < 10; i++)
            {
                Console.WriteLine(myTestArray[i]);
            }

            for (int i = 0; i < 10 / 2; i++)
            {
                string s = myTestArray[i];
                myTestArray[i] = myTestArray[myTestArray.Length() - i - 1];
                myTestArray[myTestArray.Length() - i - 1] = s;
            }

            for (int i = 0; i < 10; i++)
            {
                Console.WriteLine(myTestArray[i]);
            }

            #endregion

            #region BookTest
            var             bookProcesser  = new BookProcessor();
            DBEventListener dbBookListener = new DBEventListener(bookProcesser.GetBookDb());

            PopulateBookProcessor(bookProcesser);

            string choice = string.Empty;

            do
            {
                choice = bookProcesser.BuyBook(new BookProcessor.OutOfStockDelegate(ProcessOutofStock));
            } while (choice != "q");


            #endregion BookTest

            #region FacadeTest
            Customer customerOne = new Customer("Bob Jones", 150000);
            Customer customerTwo = new Customer("Sally Smith", 90000);

            MortgageApprover mortgageApprove = new MortgageApprover();

            Console.WriteLine(
                mortgageApprove.CheckForApproval(customerOne)
                    ? "Customer {0} is approved!"
                    : "Custerom {0} is declined :(", customerOne.Name);

            Console.WriteLine(
                mortgageApprove.CheckForApproval(customerTwo)
                    ? "Customer {0} is approved!"
                    : "Custerom {0} is declined :(", customerTwo.Name);
            #endregion

            #region AdapterTest
            AdapterPattern adapterTest = new AdapterPattern();

            adapterTest.TestAdapterPattern();
            #endregion
        }