Command Pattern — Concept Check
Questions on Command Pattern. Command encapsulates a request as an object, enabling undo/redo, queuing, logging, and parameterisation of operations.
Questions in this quiz
8 questions on Command Pattern — Concept Check. Work through them here, then start the quiz to answer them and see your score.
1.A developer wants to implement undo functionality in a text editor using the Command pattern. Which role is responsible for maintaining the history of commands?
- ACommand
- BReceiver
- CConcreteCommand
- DInvoker
2.In a multi-threaded application, commands are enqueued and executed by a worker thread. What pattern does this describe?
- AMacro Command
- BCommand Queue
- CRunnable Pattern
- DCommand Interface
3.A developer uses Runnable instead of a full Command pattern for a task without undo. Why is this appropriate?
- ARunnable is faster than Command
- BRunnable is simpler for fire-and-forget tasks
- CCommand pattern is only for GUIs
- DRunnable supports undo operations
4.A text editor uses the Command pattern to manage text changes. What role does the TextEditor class play?
- ACommand
- BReceiver
- CConcreteCommand
- DInvoker
5.A developer mistakenly believes that the Invoker needs to know the type of each command it executes. Why is this incorrect?
- AInvoker stores commands by type
- BInvoker needs to implement each command
- CInvoker triggers commands without knowing their type
- DInvoker must validate command types
6.A macro command is used to execute multiple commands in sequence. What additional feature does it typically support?
- AAutomatic retries
- BParallel execution
- CType checking
- DUndo in reverse order
7.A developer uses Callable to execute a command that returns a result. What is a key difference from using Runnable?
- ACallable returns a result
- BCallable is only for GUIs
- CCallable supports undo
- DCallable is faster
8.A developer claims that using the Command pattern is mandatory for all Java applications. What is a flaw in this statement?
- ARunnable suffices for simple tasks
- BCommand pattern is obsolete
- CCommand pattern is only for logging
- DJava does not support Command pattern