001package headfirst.combining.decorator;
002
003public class DuckSimulator {
004        public static void main(String[] args) {
005                DuckSimulator simulator = new DuckSimulator();
006                simulator.simulate();
007        }
008
009        void simulate() {
010                Quackable mallardDuck = new QuackCounter(new MallardDuck());
011                Quackable redheadDuck = new QuackCounter(new RedheadDuck());
012                Quackable duckCall = new QuackCounter(new DuckCall());
013                Quackable rubberDuck = new QuackCounter(new RubberDuck());
014                Quackable gooseDuck = new GooseAdapter(new Goose());
015
016                System.out.println("\nDuck Simulator: With Decorator");
017
018                simulate(mallardDuck);
019                simulate(redheadDuck);
020                simulate(duckCall);
021                simulate(rubberDuck);
022                simulate(gooseDuck);
023
024                System.out.println("The ducks quacked " +
025                                QuackCounter.getQuacks() + " times");
026        }
027
028        void simulate(Quackable duck) {
029                duck.quack();
030        }
031}