A coffee vending machine is an automated machine that prepares and dispenses coffee and related beverages (like espresso, cappuccino, or tea) to users with minimal human intervention.
Users typically interact with the machine by:
Internally, the machine manages ingredient inventory (coffee powder, water, milk, sugar), tracks user inputs, processes payments, and maintains operational states (e.g., idle, dispensing, out of service).
In this chapter, we will explore the low-level design of a coffee vending machine in detail.
Lets start by clarifying the requirements:
Before starting the design, it's important to ask thoughtful questions to uncover hidden assumptions and better define the scope of the system.
Here is an example of how a conversation between the candidate and the interviewer might unfold:
Candidate: Should the machine support multiple beverage types?
Interviewer: Yes, the machine should support a configurable menu of beverage types like espresso, cappuccino, latte, black coffee, etc.
Candidate: Does the system need to support payment functionality?
Interviewer: No, we can skip payment handling. You can assume this machine is used in environments like offices or homes where no payment is required.
Candidate: Should the machine allow customization, such as choosing sugar level or milk quantity?
Interviewer: Yes, users should be able to make basic customizations such as choosing sugar and milk levels per beverage.
Candidate: Should the machine track inventory of ingredients like coffee, milk, and sugar?
Interviewer: Yes, it should maintain an internal inventory for all ingredients.
Candidate: How should the system handle situations where some ingredients are unavailable?
Interviewer: The system should notify the user with an appropriate message.
Candidate: Does the machine need to support concurrent user interactions?
Interviewer: No, assume the machine handles one request at a time.
Candidate: Should the machine support an admin interface for restocking and maintenance?
Interviewer: Yes, an admin should be able to view current inventory levels and refill or reset the machine as needed.
With the scope clarified, we can now summarize the core system requirements.