What it is good for

As you already saw, the null object design pattern is already incorporated in Scala (and newer versions of Java) through the use of Option (Optional in Java). This makes it really easy to use and shows the power of the language once more. Using null objects makes our code look much more readable and removes the need to take extra care when a value is null. It also reduces the risk of bugs.

Get Scala Design Patterns - Second Edition 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.