Пример #1
0
        public void Compound_Strategy_Behavior()
        {
            DuckSimulator duckSim = new DuckSimulator();
            IQuackable    duck1   = new MallardDuck();
            IQuackable    duck2   = new DuckCall();

            duckSim.Simulate(duck1);
            duckSim.Simulate(duck2);
        }
Пример #2
0
        public void Compound_Adapter_Behavior()
        {
            DuckSimulator duckSim      = new DuckSimulator();
            IQuackable    duck1        = new RubberDuck();
            Goose         goose        = new Goose();
            IQuackable    gooseAdapter = new GooseAdapter(goose);

            duckSim.Simulate(duck1);
            duckSim.Simulate(gooseAdapter);
        }
Пример #3
0
        public void Compound_Decorator_Behavior()
        {
            DuckSimulator duckSim      = new DuckSimulator();
            IQuackable    duck1        = new QuackCounter(new RubberDuck());
            Goose         goose        = new Goose();
            IQuackable    gooseAdapter = new QuackCounter(new GooseAdapter(goose));

            duckSim.Simulate(duck1);
            duckSim.Simulate(gooseAdapter);

            Assert.AreEqual(2, QuackCounter.GetQuackCount());
        }
Пример #4
0
        public void VariableDuckQuackTest()
        {
            var duckSimulator                 = new DuckSimulator();
            AbstractDuckFactory  factory      = new CountingDuckFactory();
            AbstractGooseFactory gooseFactory = new GooseFactory();

            duckSimulator.Simulate(factory, gooseFactory);
        }
Пример #5
0
        public void Compound_Observer()
        {
            DuckSimulator sim         = new DuckSimulator();
            Flock         flockDucks  = new Flock();
            IDuckFactory  duckFactory = new DuckCounterFactory();

            flockDucks.Add(duckFactory.CreateMallardDuck());
            flockDucks.Add(duckFactory.CreateRubberDuck());
            flockDucks.Add(duckFactory.CreateRedheadDuck());
            flockDucks.Add(duckFactory.CreateDuckCall());
            flockDucks.Add(new GooseAdapter(new Goose()));

            flockDucks.RegisterObservers(new QuackologistObserver());

            sim.Simulate(flockDucks);
            Assert.AreEqual(4, QuackCounter.GetQuackCount());
        }
Пример #6
0
        public void Compound_Composite()
        {
            DuckSimulator sim = new DuckSimulator();

            Flock        flockDucks  = new Flock();
            IDuckFactory duckFactory = new DuckFactory();

            flockDucks.Add(duckFactory.CreateMallardDuck());
            flockDucks.Add(duckFactory.CreateMallardDuck());
            flockDucks.Add(duckFactory.CreateMallardDuck());
            flockDucks.Add(duckFactory.CreateMallardDuck());
            Flock flockRubberDucks = new Flock();

            flockRubberDucks.Add(duckFactory.CreateRubberDuck());
            flockRubberDucks.Add(duckFactory.CreateRubberDuck());
            flockRubberDucks.Add(duckFactory.CreateRubberDuck());
            flockDucks.Add(flockRubberDucks);

            sim.Simulate(flockDucks);
        }
Пример #7
0
        public static void Start()
        {
            var simulator = new DuckSimulator();

            simulator.Simulate(new CountingDuckFactory());
        }