← Back to PatternPip

COMMAND / PRACTICE

One remote.
Requests worth remembering.

You met Command in a text editor. Now connect undoable smart-home controls to different receivers.

YOUR MISSION / SMART-HOME REQUESTS

Restore the setting.
Keep the remote generic.

A lamp starts at 30%. Its command should set a requested brightness, remember the previous value and restore it on undo. History manages the same requests across undo and redo.

This is a local simulation. The goal is both correct state and a remote that accepts commands without knowing how devices work.

01 / DESIGN THE REQUEST

Make three design choices.

Choose the behavior owner, undo data and redo policy. Every test runs your selected combination.

Who should know how a lamp changes?

Try your own design first. Hints and retries are unlimited.

02 / INVOKE · RESTORE · REPEAT

Who remembers the previous setting?

Local simulation

The lamp started at 30%. Set it to 80%, then undo. The earlier value must come back.

Predict first (optional): what is the final setting?
INVOKER / HOME REMOTE

Press a request

HomeRemote hands Command objects to its history.

invoke the stored behavior ↓
CONCRETE COMMAND

SetBrightness

Choose how this request restores its receiver.

update the receiver ↓
RECEIVER / LAMP

30%

0 receiver writes reached in this trace.

Recorded history

Undo · 0

Empty

Redo · 0

Empty

A new request should clear the old redo branch. Back replays snapshots without changing devices.

Predictions are optional. Step through, or play and pause.

Complete your design choices, then test an actual request sequence.

See the code behind your design TypeScript

03 / EXTEND YOUR DESIGN

A different device. The same remote.

An existing Thermostat provides setTemperature(value). Connect an undoable 24 °C request without making the remote understand temperatures.

First verify all three lamp cases with the same assembly.

Select all required edits

Compare with a complete solution

Hints, retries and predictions carry no penalty. Loading the solution clears verification so you can test it yourself.