This Java program demonstrates the behavior of different types of ducks using the Strategy Pattern. It implements separate interfaces for flying, swimming, and quacking behaviors, which are dynamically assigned to different duck types.
- Ducks: Implements different types of ducks, including
MallardDuck,RedHeadDuck, andRubberDuck. - Strategy Pattern: Uses
FlyBehaviour,SwimBehaviour, andQuackBehaviourinterfaces with concrete implementations. - Behavioral Implementations:
FlyBehaviour:CanFly,CannotFlySwimBehaviour:Floating,SwimWithLegsQuackBehaviour:Quack,Squeak
- Extensibility: New duck types and behaviors can be added easily.
Duck.java: Abstract class defining common duck properties and behaviors.FlyBehaviour.java: Interface for flying behavior.SwimBehaviour.java: Interface for swimming behavior.QuackBehaviour.java: Interface for quacking behavior.CanFly.java,CannotFly.java: Implementations ofFlyBehaviour.Floating.java,SwimWithLegs.java: Implementations ofSwimBehaviour.Quack.java,Squeak.java: Implementations ofQuackBehaviour.MallardDuck.java,RedHeadDuck.java,RubberDuck.java: Specific duck implementations.Main.java: Entry point of the program.