001package headfirst.strategy; 002 003public abstract class Duck { 004 FlyBehavior flyBehavior; 005 QuackBehavior quackBehavior; 006 007 public Duck() { 008 } 009 010 public void setFlyBehavior (FlyBehavior fb) { 011 flyBehavior = fb; 012 } 013 014 public void setQuackBehavior(QuackBehavior qb) { 015 quackBehavior = qb; 016 } 017 018 abstract void display(); 019 020 public void performFly() { 021 flyBehavior.fly(); 022 } 023 024 public void performQuack() { 025 quackBehavior.quack(); 026 } 027 028 public void swim() { 029 System.out.println("All ducks float, even decoys!"); 030 } 031}