A vending machine is a self-service automated device that dispenses items like snacks, beverages, or other products to users without the need for human assistance. These machines are commonly found in places like offices, schools, airports, and train stations.
Users typically interact with the machine by:
In this chapter, we will explore the low level design of a 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 discussion between the candidate and the interviewer might unfold:
Candidate: Should the machine allow multiple transactions to run concurrently?
Interviewer: No, only one transaction should be allowed at a time.
Candidate: Should the vending machine support multiple payment methods, such as coins, notes, and digital payments?
Interviewer: For this version, let’s support only coin-based transactions. The machine should accept fixed denominations such as $1, $5, and $10.
Candidate: Should the machine be able to return change if the inserted amount exceeds the item price?
Interviewer: Yes, returning the correct change is an important part of the system.
Candidate: Can users cancel a transaction midway and get their money back?
Interviewer: Yes, users should be able to cancel a transaction any time before an item is dispensed. The full amount inserted should be refunded.
Candidate: Do we need to support admin operations such as restocking items or updating item prices?
Interviewer: The system should support restocking items or adding new items with a specified quantity. For simplicity, let's skip price updates for now.
Candidate: Do we need to track and log transaction history or sales data?
Interviewer: No need to maintain detailed transaction history. However, we can display intermediate states during a transaction
Candidate: Should the machine generate a receipt after the purchase?
Interviewer: No, receipt generation is not required for this version.
After gathering the details, we can summarize the key system requirements.
After the requirements are clear, lets identify the core entities/objects we will have in our system.