O'Reilly logo

Design Patterns in Modern C++: Reusable Approaches for Object-Oriented Software Design by Dmitri Nesteruk

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

© Dmitri Nesteruk 2018

Dmitri Nesteruk, Design Patterns in Modern C++, https://doi.org/10.1007/978-1-4842-3603-1_19

19. Null Object

Dmitri Nesteruk

(1)St. Petersburg, Russia

We don’t always choose the interfaces we work with. For example, I’d rather have my car drive me to my destination by itself, without me having to give 100% of my attention to the road and the dangerous lunatics driving next to me. And it’s the same with software: sometimes you don’t really want a piece of functionality, but it’s built into the interface. So what do you do? You make a Null Object.

Scenario

Suppose you inherited a library that uses the following interface :

1   struct Logger2   {3     virtual ~Logger() = default;4     virtual void info(const string& s) = 0;5      ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required