Chapter 7. Of Visitors and Chains of Responsibilities

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 ...

Get Scala Functional Programming Patterns now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.