コード例 #1
0
        static void TestDucksQuacking()
        {
            var countingDuckFactory = new CountingDuckFactory();
            var duckFactory = new DuckFactory();

            IQuackable mallarDuck;
            IQuackable duckCallDuck;
            IQuackable fakeDuckIsAGoose;
            IQuackable rubberDuck;
            IQuackable redheadDuck;

            var flock = new Flock();

            CreateDucks(countingDuckFactory, out mallarDuck, out duckCallDuck, out fakeDuckIsAGoose, out rubberDuck, out redheadDuck);

            flock.addQuackable(mallarDuck);
            flock.addQuackable(duckCallDuck);
            flock.addQuackable(fakeDuckIsAGoose);
            flock.addQuackable(rubberDuck);
            flock.addQuackable(redheadDuck);

            SimulateQuacks(redheadDuck, duckCallDuck, fakeDuckIsAGoose, mallarDuck, rubberDuck);

            flock.quack();

            Console.WriteLine("Number of Quacks: {0}", QuackCounter.getQuacks());

            CreateDucks(duckFactory, out mallarDuck, out duckCallDuck, out fakeDuckIsAGoose, out rubberDuck, out redheadDuck);

            flock.addQuackable(mallarDuck);
            flock.addQuackable(duckCallDuck);
            flock.addQuackable(fakeDuckIsAGoose);
            flock.addQuackable(rubberDuck);
            flock.addQuackable(redheadDuck);

            flock.quack();
            flock.quack();
            flock.quack();

            flock.quack();

            SimulateQuacks(redheadDuck, duckCallDuck, fakeDuckIsAGoose, mallarDuck, rubberDuck);

            Console.WriteLine("Number of Quacks: {0}", QuackCounter.getQuacks());

            Console.ReadKey();
        }
コード例 #2
0
        static void Main(string[] args)
        {
            var observer = new Observer();
            var countingDuckFactory = new CountingDuckFactory();

            var mallarDuck = countingDuckFactory.createMallarDuck();
            //mallarDuck.addObserver(observer);

            var rubberDuck = countingDuckFactory.createRubberDuck();
            //rubberDuck.addObserver(observer);

            var redheadDuck = countingDuckFactory.createRedHeadDuck();
            //redheadDuck.addObserver(observer);

            var duckCallDuck = countingDuckFactory.createDuckCallDuck();
            //duckCallDuck.addObserver(observer);

            var fakeDuckIsAGoose = countingDuckFactory.createGooseDucky();
            //fakeDuckIsAGoose.addObserver(observer);

            //mallarDuck.quack();
            //rubberDuck.quack();
            //redheadDuck.quack();
            //duckCallDuck.quack();
            //fakeDuckIsAGoose.quack();

            var flock = new Flock();
            flock.addQuackable(mallarDuck);
            flock.addQuackable(duckCallDuck);
            flock.addQuackable(fakeDuckIsAGoose);
            flock.addQuackable(rubberDuck);
            flock.addQuackable(redheadDuck);
            //flock.addObserver(observer);
            flock.quack();

            Console.ReadKey();
        }