In this chapter, we will look at two important design patterns, namely visitors and chains of responsibilities. These patterns help us model real-world scenarios in a pretty neat fashion. Let's first look at the problem domain.
Rakesh and Nita are happily married. One fine evening, Rakesh gets pleasantly surprised as Prakash comes visiting. Prakash is his childhood buddy and is in town on business. Prakash gets to know of Rakesh living in the same town and comes home, and the buddies meet after a span of many years. Prakash is meeting his friend's wife for the first time, though. They greet each other, well, a little formally. Prakash and Rakesh, on the other hand, back slap each other and enquire about each other's family and have a lot of memories to reminisce about.
We can imagine a similar situation ensuing when Nita's schoolmates come visiting the couple. Rakesh and Nita's mates would greet each other a little formally. The behavior...