Bird
0
0

Why is it important to avoid using ordinal values (like enum.ordinal()) directly for logic decisions in systems using enums like VehicleType and SpotType?

hard🧠 Conceptual Q10 of 15
LLD - Design — Parking Lot System
Why is it important to avoid using ordinal values (like enum.ordinal()) directly for logic decisions in systems using enums like VehicleType and SpotType?
AOrdinal values are strings and slow to compare.
BOrdinal values are always zero, making them useless.
COrdinal values can change if enum order changes, causing bugs.
DOrdinal values are deprecated and not supported.
Step-by-Step Solution
Solution:
  1. Step 1: Understand enum ordinal behavior

    Ordinal returns position index of enum constant, which depends on declaration order.
  2. Step 2: Analyze risks of using ordinal in logic

    If enum order changes, ordinal values change, breaking logic relying on fixed numbers.
  3. Final Answer:

    Ordinal values can change if enum order changes, causing bugs. -> Option C
  4. Quick Check:

    Avoid ordinal for logic due to order dependency [OK]
Quick Trick: Never rely on enum ordinal for stable logic [OK]
Common Mistakes:
MISTAKES
  • Assuming ordinal is constant
  • Using ordinal as unique ID
  • Ignoring enum order changes

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More LLD Quizzes