Design the control software for a building with several elevators. People press a button on a floor to call a lift, then press a floor number inside it. The system decides which lift goes where and moves them one floor at a time.
Name what a request is and what a lift remembers.
We have a story but no objects. What exactly is pressed, and what does a lift need to remember? A `Request` is a floor and a direction. An `Elevator` knows which floor it is on and keeps a set of **target floors** it still has to visit. `step()` moves it one floor. A set of targets means a lift does not care *who* asked or in what order: it just knows the floors it must stop at. The simplest data that answers the question wins. A set loses the order of requests. That is fine for SCAN, which serves floors by position, not by arrival time.
Make the lift's behaviour depend on what it is doing.
`step()` would need a pile of `if` statements: if idle and a target exists pick a direction, if moving up and nothing above then reverse, and so on. Every new rule adds another branch. An `ElevatorState` interface with three implementations. The lift holds one state object and forwards `step()` to it. Each state decides how to move and which state comes next. This is the **State** pattern. 'Moving up' keeps going while there are targets above, stops at them, and only then hands over to 'moving down' or 'idle'. SCAN falls out of the structure. Three small classes instead of one method. It pays off the moment you add a fourth state such as 'doors open' or 'out of service'.
Decide which lift answers each call.
Each lift can move, but nobody decides which lift a hall call goes to. An `ElevatorController` owns all the lifts and receives hall calls. It asks a `DispatchStrategy` which lift should take each call. `tick()` advances every lift by one step. Dispatch is a rule that changes (nearest, least busy, zoned for rush hour), so it is a **Strategy**. The controller stays the same whichever rule you plug in. 'Nearest lift' is easy but can starve a far floor if nearby traffic never stops. A cost function (distance plus current load) is fairer and still fits behind the same interface.
Let screens follow a lift without the lift knowing about them.
Floor indicators, the lobby screen and a maintenance dashboard all want to know where a lift is. If the lift calls each of them by name it depends on all of them. An `ElevatorObserver` interface and a list of observers inside `Elevator`. Every time the floor changes, the lift calls `onFloorChanged()` on each. `FloorDisplay` is one observer. This is the **Observer** pattern: the lift only knows the interface. Adding a mobile-app notifier means adding a class, not editing `Elevator`. Notifications run during `step()`, so a slow observer slows the lift. In real systems observers are told asynchronously.