Пример #1
0
        static void Main(string[] args)
        {
            try
            {
                IFactory factory = new StudentFactory(6.3, true);
                var      student = factory.CreateStudent();
                Console.WriteLine(student.InfoAboutStudent);

                IFactory factory1 = new StudentFactory(4, false);
                var      student2 = factory1.CreateStudent();
                Console.WriteLine(student2.InfoAboutStudent);

                IFactory factory2 = new StudentFactory(9, false);
                var      student3 = factory2.CreateStudent();
                Console.WriteLine(student3.InfoAboutStudent);

                IFactory factory3 = new StudentFactory(0, false);
                var      student4 = factory3.CreateStudent();
                Console.WriteLine(student4.InfoAboutStudent);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }

            Console.ReadLine();
        }
Пример #2
0
        static void Main(string[] args)
        {
            Console.WriteLine("---------- using factory ------------");
            var studentFactory = new StudentFactory();
            var student        = studentFactory.CreateStudent("special");
            var student2       = studentFactory.CreateStudent("normal");

            Console.WriteLine(student.Speak());
            Console.WriteLine(student2.Speak());

            Console.WriteLine("------------- using decorator ----------");
            var juniorWorker = new JuniorWorker();

            juniorWorker.DoWork();
            var seniorWorker = new SeniorWorker(juniorWorker);

            seniorWorker.DoWork();

            Console.WriteLine("-------------- Using singleton -------------");
            // instance will be same when used from anywhere
            GlobalObject global = GlobalObject.GetInstance();

            global.myGlobalList.ForEach(x => Console.WriteLine(x));
            global.myGlobalList.Add("Gaurav");
            global.myGlobalList.Add("Kapoor");
            global.myGlobalList.ForEach(x => Console.WriteLine(x));


            Console.WriteLine("---------------Using Adapter ---------------");
            ILogger outputLogger = new OutputterAdapter();
            var     newSystem    = new MyNewSystem(outputLogger);

            newSystem.Dowork();

            Console.WriteLine("----------------Using Template method -------------");
            Car myCar = new BMW();

            myCar.GetReadyAndDrive();


            Console.WriteLine("----------------Using Observer  -------------");
            Score myScore = new Score();

            myScore.AddObserver(new ScoreObserver());
            myScore.AddObserver(new SuperScoreObserver());
            myScore.Add(5);
            myScore.Subtract(3);
        }