Bird
Raised Fist0

How can the Command pattern be combined with a queue to support delayed execution of commands?

hard📝 Trade-off Q9 of Q15
LLD - Behavioral Design Patterns — Part 1
How can the Command pattern be combined with a queue to support delayed execution of commands?
AStore Command objects in a queue and execute them later by dequeuing.
BConvert commands to strings and store in a list.
CExecute commands immediately and then add to queue.
DUse a queue only for receivers, not commands.
Step-by-Step Solution
Solution:
  1. Step 1: Understand delayed execution

    Delayed execution means commands are stored and run later, not immediately.
  2. Step 2: Use queue with Command objects

    Storing Command objects in a queue allows invoking execute() later by dequeuing commands in order.
  3. Final Answer:

    Store Command objects in a queue and execute them later by dequeuing. -> Option A
  4. Quick Check:

    Queue + Command objects enable delayed execution [OK]
Quick Trick: Queue commands as objects for delayed execution [OK]
Common Mistakes:
MISTAKES
  • Storing commands as strings loses behavior
  • Executing immediately defeats delay
  • Queuing receivers instead of commands

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More LLD Quizzes