protected function simulate($duckFactoryOrQuackable)
 {
     if ($duckFactoryOrQuackable instanceof AbstractDuckFactory) {
         $redheadDuck = $duckFactoryOrQuackable->createRedheadDuck();
         $duckCall = $duckFactoryOrQuackable->createDuckCall();
         $rubberDuck = $duckFactoryOrQuackable->createRubberDuck();
         $gooseDuck = new GooseAdapter(new Goose());
         println("\nDuck Simulator: With Composite - Flocks");
         $flockOfDucks = new Flock();
         $flockOfDucks->add($redheadDuck);
         $flockOfDucks->add($duckCall);
         $flockOfDucks->add($rubberDuck);
         $flockOfDucks->add($gooseDuck);
         $flockOfMallards = new Flock();
         $mallardOne = $duckFactoryOrQuackable->createMallardDuck();
         $mallardTwo = $duckFactoryOrQuackable->createMallardDuck();
         $mallardThree = $duckFactoryOrQuackable->createMallardDuck();
         $mallardFour = $duckFactoryOrQuackable->createMallardDuck();
         $flockOfMallards->add($mallardOne);
         $flockOfMallards->add($mallardTwo);
         $flockOfMallards->add($mallardThree);
         $flockOfMallards->add($mallardFour);
         $flockOfDucks->add($flockOfMallards);
         println("\nDuck Simulator: Whole Flock Simulation");
         $this->simulate($flockOfDucks);
         println("\nDuck Simulator: Mallard Flock Simulation");
         $this->simulate($flockOfMallards);
         println("\nThe ducks quacked " . QuackCounter::getQuacks() . " times");
     } else {
         if ($duckFactoryOrQuackable instanceof Quackable) {
             $duckFactoryOrQuackable->quack();
         }
     }
 }
 protected function simulate(Quackable $duck = NULL)
 {
     if ($duck == NULL) {
         $mallardDuck = new QuackCounter(new MallardDuck());
         $redheadDuck = new QuackCounter(new RedheadDuck());
         $duckCall = new QuackCounter(new DuckCall());
         $rubberDuck = new QuackCounter(new RubberDuck());
         $gooseDuck = new GooseAdapter(new Goose());
         println("\nDuck Simulator: With Decorator");
         $this->simulate($mallardDuck);
         $this->simulate($redheadDuck);
         $this->simulate($duckCall);
         $this->simulate($rubberDuck);
         $this->simulate($gooseDuck);
         println("The ducks quacked " . QuackCounter::getQuacks() . " times");
     } else {
         $duck->quack();
     }
 }
 protected function simulate($duckFactoryOrQuackable)
 {
     if ($duckFactoryOrQuackable instanceof AbstractDuckFactory) {
         $mallardDuck = $duckFactoryOrQuackable->createMallardDuck();
         $redheadDuck = $duckFactoryOrQuackable->createRedheadDuck();
         $duckCall = $duckFactoryOrQuackable->createDuckCall();
         $rubberDuck = $duckFactoryOrQuackable->createRubberDuck();
         $gooseDuck = new GooseAdapter(new Goose());
         println("\nDuck Simulator: With Abstract Factory");
         $this->simulate($mallardDuck);
         $this->simulate($redheadDuck);
         $this->simulate($duckCall);
         $this->simulate($rubberDuck);
         $this->simulate($gooseDuck);
         println("The ducks quacked " . QuackCounter::getQuacks() . " times");
     } else {
         if ($duckFactoryOrQuackable instanceof Quackable) {
             $duckFactoryOrQuackable->quack();
         }
     }
 }