Call the MallardDuck CFC performFly function: I'm flying with wings
Note the MallardDuck's performFly function is inherited from the Duck CFC. The performFly function merely calls the fly method of whatever object is set as the value of the Duck's flyBehavior variable. For the MallarDuck the flyBehavior is set to equal an object of type FlyWithWings. So the fly function of the FlyWithWings CFC will be called.Call the MallardDuck CFC swim function: I'm swimming
Note the swim behavior is inherited from the Duck CFC.
Call the DecoyDuck CFC performFly function: I cannot fly
Note the DecoyDuck's fly behavior is defined by the FlyNoWay CFC.Call the DecoyDuck CFC swim function: I'm swimming
Note the swim behavior is inherited from the Duck CFC.Change the DecoyDuck object's fly behavior by creating a FlyRocketPowered object and passing that object to the DecoyDuck's setFlyBehavior function.
Call the DecoyDuck CFC performFly function after changing the fly behavior: I'm flying with a rocket!
Note the DecoyDuck's fly behavior is now defined by the FlyRocketPowered CFC.