I went straight for inheritance because it felt natural, had a base RollerCoaster class and overrode a score() method in each subclass.
Start by clarifying requirements and assumptions, then design a class hierarchy for coasters with a separate scoring strategy interface. Walk through key classes and methods, and compare embedding scoring logic in the hierarchy versus using the Strategy pattern, highlighting trade-offs in flexibility, maintainability, and complexity.
Pro tip: Emphasize that the Strategy pattern aligns with the Open/Closed Principle, allowing new scoring algorithms without modifying coaster classes—a key consideration for scalable systems like those at Zoox.
Ask questions to understand scope: What coaster attributes are available? Are scoring strategies fixed or dynamic? Should scoring be extensible? State assumptions to guide the design.
Create an abstract Coaster class with common attributes (speed, height, length, thrill rating) and methods. Subclasses like WoodenCoaster, SteelCoaster, etc., can add type-specific behavior.
Define a ScoringStrategy interface with a method like calculateScore(Coaster). Implement concrete strategies (e.g., SpeedBasedScoring, ThrillBasedScoring). Coaster holds a reference to a strategy.
Show how a Coaster object delegates scoring to its strategy. Discuss how strategies can be swapped at runtime and how new strategies can be added without modifying coaster classes.
Compare embedding scoring in the hierarchy (simpler but rigid, violates Open/Closed) versus Strategy pattern (flexible, follows composition over inheritance, but adds indirection). Mention when each is appropriate.
AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.