You guessed it, there is a pattern we can use. It's called the composit pattern and
it lets us model
sets of elements that may or may not contain other similar elements. Usually, the elements of a
composite structure are represented in some sort of tree structure, but they don't have to be.
However, we can model our flocks of flocks at a tree. At the root of the tree is a Flock object, It
contains individual quackable elements, or other flocks. This structure can recurse until we have all
leaf nodes (individual quackables).
The key to the Composite pattern is that we design the elements so that the compound
elements
support the same messages as the individual elements. A diagram of the Composit pattern is:
Now we only need to ask the appropriate question of the flock to get the answers we
need and it
takes care of sub-flocks and so on. Make sure you can walk through how this might handle a
simple request like getQuackCount().