Null Object Pattern

Noun · Development

Definitions

  1. A design pattern in which a special object implementing the expected interface but performing no operations (no-ops) is used in place of null references, eliminating the need for null checks throughout the codebase and allowing polymorphism to handle the 'absent' case gracefully.

    In plain English: Using a do-nothing placeholder object instead of 'nothing' so the rest of the code doesn't have to keep checking whether something exists.

    Example: "Instead of checking if the logger is null everywhere, we inject a NullLogger that silently discards messages."

Related Terms