Bird
0
0
LLDsystem_design~12 mins

Null Object pattern in LLD - Architecture Diagram

Choose your learning style9 modes available
System Overview - Null Object pattern

The Null Object pattern provides a default object that represents a "do nothing" or "empty" behavior instead of using null references. This helps avoid null checks and simplifies code by ensuring that all objects respond to the same methods safely.

Key requirements include seamless substitution of null objects, consistent interface implementation, and preventing null pointer errors.

Architecture Diagram
User
  |
  v
Client Code
  |
  v
+-------------------+
| Abstract Interface |
+-------------------+
    /           \
   /             \
Real Object    Null Object
(Service)     (Do Nothing)
    |               |
    v               v
  Business       Empty Behavior
  Logic          Implementation
Components
User
actor
Initiates requests that require service objects
Client Code
component
Uses objects through a common interface without null checks
Abstract Interface
interface
Defines common methods for real and null objects
Real Object
service
Implements actual business logic
Null Object
service
Implements empty behavior to avoid null checks
Request Flow - 5 Hops
UserClient Code
Client CodeAbstract Interface
Client CodeReal Object or Null Object
Real Object or Null ObjectClient Code
Client CodeUser
Failure Scenario
Component Fails:Null Object
Impact:If Null Object is missing or incorrectly implemented, client code may encounter null pointer errors or require explicit null checks.
Mitigation:Ensure Null Object fully implements the interface with safe default behavior to prevent null checks and errors.
Architecture Quiz - 3 Questions
Test your understanding
What is the main purpose of the Null Object in this pattern?
ATo provide a default do-nothing implementation to avoid null checks
BTo replace the real object with a faster version
CTo handle database connections
DTo log errors when null values occur
Design Principle
The Null Object pattern simplifies client code by providing a safe default object that implements the expected interface, eliminating the need for null checks and reducing errors.