Skip to main content

Summary & Key Takeaways

Editorial

Design Recap

Let's retrace our journey from blank page to working system.

TutorialWhat We DidKey Output
Getting ReadyScoped the problem, identified real-world contextProblem boundaries, learning goals
RequirementsDefined R1-R10 functional + NF1-NF5 non-functionalRequirement specification
Use Case DiagramIdentified 3 actors, 10 use casesActor-use case relationships
State MachineModeled elevator states + door sub-states2 state machines with transitions
Class DiagramDesigned 18 classes, interfaces and enumsComplete structural blueprint
Scheduling AlgorithmsImplemented FCFS, SCAN, LOOK with traced examplesAlgorithm comparison, complexity analysis
Code ImplementationFull Python + Java for every classRunnable code matching the class diagram
Design PatternsJustified Strategy, State, Observer choicesPattern rationale + rejected alternatives
Testing & Edge CasesUnit + integration tests, 6 edge casesComprehensive test coverage

Architecture at a Glance

Architecture overview of the Elevator System: all 18 types as named boxes, coloured by four layers — user interface (HallButton, ElevatorPanel, FloorDisplay), control (ElevatorSystem, Dispatcher), core domain (Elevator, Door, Floor, Request, the ElevatorObserver interface and the Direction, DoorStatus, ElevatorState and RequestType enums) and strategy (the SchedulingStrategy interface, FCFSStrategy, SCANStrategy, LOOKStrategy) — with all 22 relationships, no two lines crossing. Compositions: ElevatorSystem has its Floors, manages its Elevators and owns the Dispatcher; Elevator has its Door and its ElevatorPanel; Floor has one or two HallButtons and shows its FloorDisplay. Associations: the Dispatcher schedules the Elevators and uses a SchedulingStrategy; an Elevator serves its Requests and notifies its ElevatorObservers. Realizations: FCFSStrategy, SCANStrategy and LOOKStrategy implement SchedulingStrategy; FloorDisplay implements ElevatorObserver. Dependencies: HallButton and ElevatorPanel create Requests; Elevator uses the SchedulingStrategy handed to move() and the Direction and ElevatorState enums; Door uses DoorStatus; Request uses RequestType.

Component count: 4 enums + 2 interfaces + 12 classes = 18 total. This is typical for a medium-complexity design problem.

Relationship summary:

  • Composition: ElevatorSystem owns Elevators, Floors, and the Dispatcher. Elevator owns its Door and ElevatorPanel. Floor owns HallButtons and FloorDisplay.
  • Association: Dispatcher references Elevators and a SchedulingStrategy. Elevator serves its Requests and notifies its ElevatorObservers.
  • Implementation: FCFSStrategy, SCANStrategy, LOOKStrategy implement the SchedulingStrategy interface. FloorDisplay implements ElevatorObserver.
  • Dependency: HallButton and ElevatorPanel create Request objects. Elevator uses the SchedulingStrategy handed to move(), and the Direction and ElevatorState enums; Door uses DoorStatus; Request uses RequestType.

Patterns Applied

PatternWhere AppliedWhy This Pattern
Strategy (Fundamentals S12)Scheduling algorithms — SchedulingStrategy interface with 3 implementationsRuntime algorithm swapping without modifying Dispatcher
State (Fundamentals S4)The car's one ElevatorState enum, set only by move() and stop(), read by the strategies to pick a carClean state transitions in one place; the car never moves with its doors open — move() closes them before it leaves
Observer (Fundamentals S12)Floor displays updated via ElevatorObserverDecouples elevators from display components, easy to add new observer types

SOLID Compliance

Our design aligns with all five SOLID principles:

Single Responsibility (SRP): Each class has one reason to change.

  • Elevator manages car state and movement — NOT scheduling.
  • Dispatcher manages request routing — NOT elevator mechanics.
  • Door manages open/close — NOT elevator state transitions.

Open/Closed (OCP): The system is open for extension, closed for modification.

  • Add a new scheduling algorithm → implement SchedulingStrategy, no changes to Dispatcher or Elevator.
  • Add a new observer (monitoring dashboard) → implement ElevatorObserver, no changes to Elevator.

Liskov Substitution (LSP): Any SchedulingStrategy implementation can replace another without breaking the system. FCFSStrategy, SCANStrategy, and LOOKStrategy are fully interchangeable.

Interface Segregation (ISP): SchedulingStrategy has only 2 methods — both needed by any scheduling algorithm. ElevatorObserver has only 1 method. No client is forced to implement unused methods.

Dependency Inversion (DIP): Dispatcher depends on the SchedulingStrategy abstraction, not on concrete strategies. Elevator depends on the ElevatorObserver abstraction, not on concrete displays.

Extensions to Explore

Interview follow-ups often ask "how would you extend this?" Here are five realistic extensions and how our design accommodates them:

1. Weight/Capacity Limits
Add current_load and max_capacity to Elevator. Modify should_stop() to skip floors when full. Update select_elevator() in strategies to deprioritize full elevators. No structural changes needed.

2. VIP/Priority Elevators
Add a priority field to Request. Create a PriorityLOOKStrategy that serves high-priority requests first. The Strategy Pattern makes this a drop-in addition.

3. Destination Dispatch
Instead of UP/DOWN hall buttons, passengers enter their destination at the lobby. Changes the request model (destination known upfront) and enables better grouping. Implement as a new DestinationDispatchStrategy — the Dispatcher interface stays the same.

4. Emergency Mode
Add EMERGENCY to ElevatorState. In emergency mode, all elevators go to floor 1, open doors, and disable new requests. Add an emergency() method to ElevatorSystem that triggers the transition on all elevators.

5. Energy Optimization
During low-traffic periods, park some elevators at strategic floors (e.g., lobby, middle floor) and idle others. Implement as a ParkingStrategy that the Dispatcher uses when request volume drops below a threshold.

Key Takeaways

1. Start with requirements, not code. We wrote R1-R10 and NF1-NF5 before drawing any diagrams. Requirements drive every design decision — the class diagram is a CONSEQUENCE of requirements, not a starting point.

2. UML is a communication tool, not a formality. Our use case, state machine, and class diagrams weren't bureaucratic artifacts — they directly shaped the code. Every class in the diagram appears in the implementation. Every state in the state machine maps to an enum value.

3. Patterns solve specific problems — don't force them. We used Strategy because we genuinely needed interchangeable algorithms. We used Observer because there's a true publish-subscribe relationship. We used enum-based State instead of full State classes because 4 states didn't justify the complexity. Always ask "what problem does this pattern solve HERE?"

4. Test edge cases early. Simultaneous requests, boundary floors, duplicate presses, and single-elevator scenarios expose design flaws that aren't visible in the happy path. We identified 6 edge cases and proved our design handles each one.

5. Design for the current requirements, extend for the future. Our system handles R1-R10 without over-engineering. But the Strategy Pattern, Observer Pattern, and clean class boundaries mean that capacity limits, VIP elevators, and emergency mode can be added WITHOUT restructuring existing code.

What to Say in the Interview

When presenting your Elevator System design, structure your answer in this order:

  1. Clarify scope (2 min): "I'll design for N elevators in a single building with hall calls and cabin calls. I'm assuming no weight limits or emergency mode unless you'd like me to include those."

  2. Requirements (3 min): List 5-6 key functional requirements. Mention non-functional considerations (thread safety, response time).

  3. Key classes (5 min): Walk through the class diagram — ElevatorSystem, Elevator, Dispatcher, SchedulingStrategy, Floor. Highlight relationships (composition vs. association).

  4. Patterns (3 min): Name each pattern, where it's used, and WHY — not just what it is. "We use Strategy for scheduling because we need runtime swapping between FCFS and LOOK."

  5. One algorithm deep-dive (3 min): Trace SCAN or LOOK through a concrete example with 5-6 requests.

  6. Edge cases (2 min): Proactively mention 2-3 edge cases and how your design handles them.

Total: ~18 minutes, leaving room for interviewer questions and extensions.