Logo

Coding preview

Nullify

What this preview is

About this preview

Nullify is a cooked quant coding problem on design patterns in Cpp / Python.

Unlock full access to getcracked

Join to unlock this problem, detailed solutions, and our complete library of quant finance interview prep.

Implementing the Null Object design pattern for graceful defaults

This medium-difficulty C++ and Python design-patterns problem tests whether you can recognize and apply the Null Object pattern—a structural approach that replaces absence with a well-defined do-nothing implementation. Rather than returning pointers or optionals and forcing callers to check for null, you provide a harmless instance that conforms to the interface but performs no action.

The question uses a logger factory as its vehicle: when configuration is missing or absent, instead of throwing or returning a null pointer, the factory should instantiate and return a logger that safely ignores all operations. This pattern is especially valuable in systems where optional configuration should degrade gracefully rather than fail hard. You'll need to ensure thread-safety through single allocation (likely via static instances or a cache) and careful conformance to the logger interface.

  • Object-oriented interface contracts and polymorphism
  • Factory patterns with optional/default cases
  • Memory management and single-responsibility allocation
  • Graceful degradation vs. failure modes