We've been working with the quackologists for a while now and we just know that they're
going to
want more from us. We can imagine adding a flockID to the quackable objects and needing to
query how many quackers are in a flock. There are certainly more things than we can imagine right
now. We'd like to make it easy to add these, seemingly, ad hoc queries without a lot of effort.
There's one more pattern that we'll add to our example. This is the Visitor pattern. The Visitor
pattern is used when you want to add capabilities to a composite of objects and encapsulation
is
not important. We have composites, namely the flocks. So, we can build a IFlockVisitor interface
that will gather information about the flocks.
The Visitor pattern looks like this: