Hierarchy of the project:

  1. QuackObservable Interface Hierarchy:

  2. Observer Interface Hierarchy:

  3. Quackable Interface Hierarchy:

  4. Duck Factory Hierarchy:

  5. Duck Simulator Classes:

  6. Flock Hierarchy:

  7. Goose Classes:

    Patterns used in the project:

    1. Observer Pattern:
      • Classes/Interfaces Involved: Observer, QuackObservable, Quackologist, Observable
      • Usage: The observer pattern is used to implement the behavior where the Quackologist observes QuackObservable instances (ducks) to be notified when they quack.
    2. Decorator Pattern:
      • Classes/Interfaces Involved: Quackable, QuackCounter
      • Usage: The decorator pattern is used to add behavior (counting quacks) to the Quackable ducks. QuackCounter wraps around another Quackable and adds counting functionality.
    3. Composite Pattern:
      • Classes/Interfaces Involved: Quackable, Flock
      • Usage: The composite pattern is used to treat both individual ducks and groups of ducks uniformly. The Flock class is a composite of multiple Quackable objects, allowing them to be treated as a single unit.
    4. Factory Method Pattern:
      • Classes/Interfaces Involved: AbstractDuckFactory, DuckFactory, CountingDuckFactory
      • Usage: The factory method pattern is used to create families of related objects. AbstractDuckFactory defines the interface for creating ducks, and DuckFactory and CountingDuckFactory are concrete implementations that create different types of ducks.
    5. Adapter Pattern:
      • Classes/Interfaces Involved: GooseAdapter
      • Usage: The adapter pattern is used to make a Goose object compatible with the Quackable interface. GooseAdapter adapts the Goose class to behave like a duck.

    Classes and Interfaces - Their usages

    Interfaces:

    1. QuackObservable:
      • Responsibility: Interface for objects that can be observed.
      • Usage: Implemented by classes that need to notify observers when their state changes.
    2. Observer:
      • Responsibility: Interface for objects that observe QuackObservable subjects.
      • Usage: Implemented by classes that want to be notified when the state of QuackObservable changes.
    3. Quackable:
      • Responsibility: Interface for objects that can quack.
      • Usage: Implemented by concrete duck classes and the QuackCounter decorator. Also used by the Flock composite.
    4. QuackObservable:
      • Responsibility: Interface for objects that can be observed.
      • Usage: Implemented by classes that need to notify observers when their state changes.

    Classes:

    1. Observable:

      • Responsibility: Manages a list of observers and notifies them of changes.
      • Usage: Used by classes that implement QuackObservable to handle the registration and notification of observers.
    2. DuckCall:

      • Responsibility: Represents a duck call that can quack.
      • Usage: Creates a quacking sound, registers observers, and notifies them when quacking.
    3. Goose:

      • Responsibility: Represents a goose that can honk.
      • Usage: Honks like a goose.
    4. GooseAdapter:

      • Responsibility: Adapt a Goose to behave like a duck (Quackable).
      • Usage: Allows a goose to be used in scenarios expecting a Quackable object.
    5. MallardDuck:

      • Responsibility: Represents a mallard duck.
      • Usage: Quacks like a mallard duck, registers observers and notifies them when quacking.
    6. RedheadDuck:

      • Responsibility: Represents a redhead duck.
      • Usage: Quacks like a redhead duck, registers observers and notifies them when quacking.
    7. RubberDuck:

      • Responsibility: Represents a rubber duck.
      • Usage: Squeaks like a rubber duck, registers observers and notifies them when squeaking.

Interface

Classes