Class Diagram
Purpose of the Class Diagram
The class diagram is the structural blueprint of our Elevator System. It answers:
- What classes exist and what are their responsibilities?
- What attributes and methods does each class have?
- How do the classes relate to each other (composition, association, inheritance, implementation)?
This is the most important diagram for the Elevator System because it captures the full design: the elevator cars, the request model, the dispatcher, the scheduling strategies, and the observer-based display system. Every class we draw derives directly from a requirement (R1–R10) or a state machine state.
Identifying Classes from Requirements
Using the noun/verb extraction technique from Fundamentals S8, we analyze our requirements:
Key Nouns → Candidate Classes:
| Requirement | Nouns Found | Candidate Class |
|---|---|---|
| R1: "N floors, M elevator cars" | building, floors, elevator, cars | ElevatorSystem, Elevator, Floor |
| R2: "Hall calls from any floor" | hall call, floor, UP/DOWN button | Request (with RequestType.HALL_CALL), HallButton |
| R3: "Cabin calls from inside" | cabin call, destination, panel | Request (with RequestType.CABIN_CALL), ElevatorPanel |
| R4: "Dispatch to optimal elevator" | dispatcher, optimal | Dispatcher |
| R6: "Direction: UP, DOWN, IDLE" | direction | Direction enum |
| R7: "Interchangeable scheduling algorithm" | algorithm, FCFS, SCAN, LOOK | SchedulingStrategy interface, concrete implementations |
| R8: "Door opens and closes" | door, states | Door, DoorStatus enum |
| R9: "Floor display panel" | display, position, direction | FloorDisplay |
Key Verbs → Candidate Methods:
- "make a hall call" →
Floor.pressUp(),Floor.pressDown()— each presses itsHallButton, which creates theRequest - "make a cabin call" →
ElevatorPanel.pressFloor(int) - "dispatch elevator" →
Dispatcher.dispatch(Request) - "move to floor" →
Elevator.move(SchedulingStrategy)— one floor per call, toward the next stop the strategy it is handed picks - "should stop at floor" →
Elevator.shouldStop(int) - "open/close doors" →
Door.open(),Door.close() - "update display" →
FloorDisplay.onElevatorMoved(int, int, Direction)— theElevatorObservermethod the elevator calls with its id, floor and direction
Class Inventory
Here are all classes in our design, grouped by responsibility:
Enums (4):
Direction— UP, DOWN, IDLEDoorStatus— CLOSED, OPENING, OPEN, CLOSINGElevatorState— IDLE, MOVING_UP, MOVING_DOWN, DOOR_OPENRequestType— HALL_CALL, CABIN_CALL
Core Domain (4):
Request— a floor request with source floor, destination, direction, and typeElevator— an elevator car with current floor, direction, door, and request queueDoor— the door mechanism with status and open/close behaviorFloor— a building floor with hall buttons and a display
Control (2):
ElevatorSystem— the top-level class that composes elevators, floors, and the dispatcherDispatcher— receives hall calls and assigns each to the best elevator using the scheduling strategy (a cabin call goes straight to its own car)
Strategy (4):
SchedulingStrategy— interface definingselectElevator(Request, List<Elevator>)andgetNextStop(Elevator)FCFSStrategy— First Come First Served: assigns to the idle elevator with the fewest pending requests and sends each car to its oldest requestSCANStrategy— Elevator algorithm: sweeps in its direction to the building's edge (minFloor,maxFloor), serving the requests on the way, then reversesLOOKStrategy— Like SCAN but reverses at the last request instead of the building edge
Observer (2):
ElevatorObserver— the interface the elevator notifies:onElevatorMoved(elevatorId, floor, direction)FloorDisplay— displays current elevator positions and directions; implementsElevatorObserver
UI Components (2):
HallButton— the UP/DOWN button on each floorElevatorPanel— the button panel inside each elevator with floor buttons
Total: 18 classes, interfaces and enums (4 enums, 2 interfaces, 12 classes) — appropriate for a Medium difficulty problem (6–12 main classes + supporting enums/interfaces).
Defining Relationships
Now let's determine how these classes connect, with justification for each relationship type:
Composition (◆ — part cannot exist without the whole):
ElevatorSystem ◆→ Elevator [1..*]— Elevators are part of the system. Destroying the system destroys its elevators.ElevatorSystem ◆→ Floor [1..*]— Floors are part of the building structure.ElevatorSystem ◆→ Dispatcher [1]— The dispatcher is an internal component of the system.Elevator ◆→ Door [1]— Every elevator has exactly one door. The door doesn't exist independently.Elevator ◆→ ElevatorPanel [1]— The control panel is physically inside the elevator.Floor ◆→ HallButton [1..2]— Each floor has 1–2 hall buttons (UP only on ground, DOWN only on top, both on middle floors).Floor ◆→ FloorDisplay [1]— Each floor has a display panel.
Association (── reference, independent lifecycle):
Dispatcher ── SchedulingStrategy— The dispatcher uses a strategy but the strategy can be swapped. Neither owns the other.Elevator ── Request [0..*]— An elevator holds a queue of requests. Requests can exist before assignment.Dispatcher ── Elevator [1..*]— The dispatcher references all elevators to make dispatch decisions.
Implementation (⤑ dashed triangle):
FCFSStrategy ⤑ SchedulingStrategySCANStrategy ⤑ SchedulingStrategyLOOKStrategy ⤑ SchedulingStrategyFloorDisplay ⤑ ElevatorObserver— each floor's display implements the interface;ElevatorSystemregisters every floor's display with every elevator.
Dependency (⇢ dashed arrow — uses another type without keeping it):
Elevator ⇢ SchedulingStrategy«uses» —move(strategy)asks the strategy for the next stop. The elevator is handed the strategy for that one call (ElevatorSystem.step()passes the dispatcher's) and keeps no reference to it.HallButton ⇢ Request,ElevatorPanel ⇢ Request«creates» — pressing a button makes theRequest; the button keeps no reference to it.Elevator ⇢ Direction,Elevator ⇢ ElevatorState,Door ⇢ DoorStatus,Request ⇢ RequestType— the enums are the types of their fields.
Observer relationship:
Elevator ── ElevatorObserver [0..*]—Elevatornotifies its observers when its position or direction changes: it keeps a list ofElevatorObserverreferences and callsonElevatorMoved()on each — an association with observer semantics, through the interface, so the elevator never namesFloorDisplay.
Why Composition between ElevatorSystem and Elevator (not Aggregation)?
An elevator car is physically installed in the building's shaft — it cannot exist independently or be moved to another building. The elevator's lifecycle is bound to the system. This is hallmark composition: destroy the system, destroy the elevators.
Why Association between Dispatcher and SchedulingStrategy (not Composition)?
The scheduling strategy can be replaced at runtime without destroying the dispatcher. Multiple dispatchers could share the same strategy instance. The strategy exists independently of any dispatcher — it's a pluggable algorithm, not a physical part.
Build the Class Diagram
Build the diagram step by step, starting with the core entities and expanding outward to the strategy and observer components. Place each step's classes and predict each relationship the lesson gives a reason for — its kind, then how many — and read the reason. Then open any class in Explore to see its members, or run the Code Implementation's usage example in Objects live: the floors with their buttons and displays, the two elevators with their doors, panels and request queues, and the Request objects the cars and the dispatcher share.

Complete Class Diagram

Key Design Decisions
1. Why a unified Request class instead of separate HallCall and CabinCall classes?
Both hall calls and cabin calls share the same core data: source floor, destination, and direction. The only difference is the type field (HALL_CALL vs CABIN_CALL) and how they're created (from a floor button vs from an elevator panel). A single Request class with a RequestType enum keeps the elevator's side clean — its request queue, shouldStop() and every strategy's getNextStop() handle Request objects uniformly; the dispatcher sees only hall calls. If we needed significantly different behavior, inheritance would be justified. Here, the difference is data-only, not behavioral.
2. Why does the Dispatcher hold a reference to SchedulingStrategy (not the ElevatorSystem)?
The dispatcher is the class that decides with the scheduling algorithm and swaps it (setStrategy()); the elevators only borrow it — each step, ElevatorSystem.step() hands the dispatcher's strategy to every Elevator.move(strategy) for its next stop, so one swap reaches every car. Putting the strategy reference on ElevatorSystem would force all strategy-related calls to go through the system — adding unnecessary indirection. The dispatcher directly uses the strategy to decide which elevator handles a request. This follows the Information Expert principle (Fundamentals S7): place behavior on the class with the most relevant data.
3. Why Composition between Elevator and Door but Association between Elevator and Request?
The door is physically part of the elevator — it's installed in the car and cannot exist independently. Destroying the elevator means destroying its door. This is composition.
Requests, however, exist independently — a request is created when a button is pressed, assigned to an elevator, and then removed when served. The request's lifecycle is not bound to the elevator's. This is association: the elevator references requests, but doesn't own them.
4. Why SchedulingStrategy has both selectElevator() and getNextStop()?
These are two distinct questions the strategy answers:
selectElevator(request, elevators)— WHICH elevator should handle a new hall call? (dispatch-time decision)getNextStop(elevator)— WHERE should this elevator go next? (per-move decision)
FCFS answers these differently than SCAN. FCFS assigns to the idle elevator with the fewest pending requests and sends each car to its oldest request. SCAN assigns to the nearest elevator that is idle or already moving toward the call in its direction, and serves requests in sweep order. Both questions go through the strategy interface, keeping the algorithm fully encapsulated.
5. Why FloorDisplay as an Observer rather than polling?
A floor display must update when any elevator moves. With polling, every display would need to periodically check all elevators — wasteful when nothing has changed. With Observer (Fundamentals S12), the elevator notifies all displays when it moves or goes idle. The display is guaranteed to show current data with no polling delay. This also decouples the elevator from the display — the elevator doesn't know what's observing it; it just fires notifications.