private void Simulate(AbstractDuckFactory duckFactory, AbstractGooseFactory gooseFactory) { //IQuackable _mallardDuck = duckFactory.CreateMallardDuck(); IQuackable _redheadDuck = duckFactory.CreateRedheadDuck(); IQuackable _duckCall = duckFactory.CreateDuckCall(); IQuackable _rubberDuck = duckFactory.CreateRubberDuck(); IQuackable _gooseDuck = gooseFactory.CreateGoose(); Flock flockOfDucks = new Flock(); //flockOfDucks.Add(_mallardDuck); flockOfDucks.Add(_redheadDuck); flockOfDucks.Add(_duckCall); flockOfDucks.Add(_rubberDuck); flockOfDucks.Add(_gooseDuck); Flock flockOfMallards = new Flock(); IQuackable mallardOne = duckFactory.CreateMallardDuck(); IQuackable mallardTwo = duckFactory.CreateMallardDuck(); IQuackable mallardThree = duckFactory.CreateMallardDuck(); IQuackable mallardFour = duckFactory.CreateMallardDuck(); //IQuackable mallardFive = duckFactory.CreateMallardDuck(); flockOfMallards.Add(mallardOne); flockOfMallards.Add(mallardTwo); flockOfMallards.Add(mallardThree); flockOfMallards.Add(mallardFour); //flockOfMallards.Add(mallardFive); flockOfDucks.Add(flockOfMallards); Console.WriteLine("Duck Simulator\nFull Flock"); Simulate(flockOfDucks); Console.WriteLine("Duck Simulator\nMallard Flock"); Simulate(flockOfMallards); Console.WriteLine("Value:" + QuackCounter.NumberOfQuacks); Quackologist quackologist = new Quackologist(); flockOfDucks.RegisterObserver(quackologist); Simulate(flockOfDucks); Console.WriteLine("Утки крякнут " + QuackCounter.NumberOfQuacks + " раз"); }
public void Simulate(AbstractDuckFactory duckFactory) { IQuackable redheadDuck = duckFactory.CreateRedheadDuck(); IQuackable duckCall = duckFactory.CreateDuckCall(); IQuackable rubberDuck = duckFactory.CreateRubberDuck(); IQuackable gooseDuck = new GooseAdapter(new Goose()); Flock flockOfDucks = new Flock(); flockOfDucks.Add(redheadDuck); flockOfDucks.Add(duckCall); flockOfDucks.Add(rubberDuck); flockOfDucks.Add(gooseDuck); Flock flockOfMallards = new Flock(); IQuackable mallardOne = duckFactory.CreateMallardDuck(); IQuackable mallardTwo = duckFactory.CreateMallardDuck(); IQuackable mallardThree = duckFactory.CreateMallardDuck(); IQuackable mallardFour = duckFactory.CreateMallardDuck(); flockOfMallards.Add(mallardOne); flockOfMallards.Add(mallardTwo); flockOfMallards.Add(mallardThree); flockOfMallards.Add(mallardFour); flockOfDucks.Add(flockOfMallards); Console.WriteLine("\nDuck Simulator: With Observer"); Quackologist quackologist = new Quackologist(); flockOfDucks.RegisterObserver(quackologist); Simulate(flockOfDucks); Console.WriteLine($"\nThe ducks quacked {QuackCounter.NumberOfQuacks} times"); }