CS FundamentalsHardProduct-company design interview

A Customer may or may not have a discount policy. Instead of writing `if policy is not None: total = policy.apply(total)` everywhere, the code uses a NoDiscount class whose apply() returns the total unchanged. Which pattern is this?

  1. A. Proxy
  2. B. Strategy only, with no special name
  3. C. Null Object
  4. D. Singleton

Correct answer: C. Null Object

A Null Object is a do-nothing implementation of the interface that removes repeated null checks; it is often combined with Strategy, as here.

More Software Engineering, Git and Cloud Basics questions

Exams that ask this topic