Skip to content

jay-c-c/java-duck

Repository files navigation

Duck Simulation - Strategy Pattern

Overview

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.

Features

  • Ducks: Implements different types of ducks, including MallardDuck, RedHeadDuck, and RubberDuck.
  • Strategy Pattern: Uses FlyBehaviour, SwimBehaviour, and QuackBehaviour interfaces with concrete implementations.
  • Behavioral Implementations:
    • FlyBehaviour: CanFly, CannotFly
    • SwimBehaviour: Floating, SwimWithLegs
    • QuackBehaviour: Quack, Squeak
  • Extensibility: New duck types and behaviors can be added easily.

File Structure

  • 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 of FlyBehaviour.
  • Floating.java, SwimWithLegs.java: Implementations of SwimBehaviour.
  • Quack.java, Squeak.java: Implementations of QuackBehaviour.
  • MallardDuck.java, RedHeadDuck.java, RubberDuck.java: Specific duck implementations.
  • Main.java: Entry point of the program.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages