← Questions

Design a coffee maker

0
AmazonOO design

An object-oriented design interview question asked at Amazon. It tests object-oriented design.

Design the software for a coffee machine. It has containers for ingredients (water, coffee beans, milk, sugar, chocolate), a set of drink recipes, and the steps to brew each one. It must refuse a drink when an ingredient is too low, and adding a new recipe should be easy.

Requirements

  • Functional: list the drinks the machine can make right now; select a drink (and optionally a size or extra sugar); check every ingredient before starting and refuse with a clear reason if one is short; brew by running the recipe's steps in order (grind, heat water, brew, steam milk, mix); deduct ingredients; refill containers and warn when one is low.
  • Adding a recipe is data or a new class, not a change to the machine's code.
  • Non-functional: one drink at a time; an ingredient check and the deduction must not let two quick orders both pass on the last portion; testable without hardware.

Clarifying questions

  • Is payment part of the machine, or is it free (an office machine)?
  • Can the user customize a drink (size, strength, extra milk), and how does that change the recipe?
  • What happens if a step fails mid-brew, for example the heater faults?
  • Are recipes loaded from a configuration file or defined in code?
  • Can the machine make several drinks in parallel?

What a strong answer covers

  • Core classes: CoffeeMachine (the façade the UI calls), Recipe (name, ingredient amounts, ordered steps), Ingredient, Container (capacity, current amount, low-level threshold), Inventory (the containers, can_make(recipe), consume(recipe)), BrewStep as an interface with steps like Grind, HeatWater, Brew, SteamMilk, and a RecipeBook registry.
  • Checking all ingredients first and then deducting in one step, so a drink is never half-made because of a shortage.
  • New drinks through the recipe registry (data) and new step types through the step interface, so the machine class does not change.
  • Customization with a decorator or modifier on a recipe (extra shot, large size) rather than one class per combination.
  • Machine states (idle, brewing, out of service) and what each accepts.
  • Tests with a fake inventory and fake hardware steps.

Follow-ups

  • Add payment with coins and cards, and a refund if brewing fails.
  • Track sales and ingredient use for restocking.
  • Support recipes that depend on user profiles (a saved favorite drink).

Where it's asked

What it tests

object-oriented design

Your canvas
Draw your answer hereBoxes, arrows and notes, saved for you to come back to.Sign in to start drawing