โ Back to Spring and Spring Boot
๐ฑ Spring and Spring Boot: cheat sheet
๐จ The analogyA restaurant manager who hires the staff and tells each cook who they work with, so cooks just cook.
๐ The regular explanationA framework that creates your application's objects, wires them together and wraps them with features like web endpoints and transactions, so your own code can stick to the business logic.
- The manager reads the list of jobs the restaurant needs. Someone to take orders, someone to cook, someone to run the pantry.
- First the manager sets up the things nobody else depends on, like the pantry itself, then hires the pantry keeper who works in it.
- Next the cook is hired and told "your ingredients come from the pantry keeper." The cook never goes looking for a pantry keeper.
- Last comes the waiter, who is told which cook to bring orders to.
- The restaurant opens. Nobody hired anyone themselves. The manager did it all, so each worker only has to do their own job.
- The cashier needs someone who can take card payments. The cashier doesn't care who, as long as they can charge a card.
- On a normal day the manager hands the cashier the real card machine.
- A customer pays and real money moves.
- On practice day the manager swaps in a pretend card machine. The cashier doesn't notice and still just says "charge".
- Practice payments go nowhere, so nobody's card gets charged while you test.
- A customer asks for order number 7. The head waiter at the door takes every request.
- The head waiter knows which station handles orders, and passes the request there.
- The waiter asks the cook, and the cook asks the pantry keeper. Each knows only the next person in line.
- The pantry keeper fetches the order from the storeroom.
- The order travels back up the line to the head waiter.
- The head waiter writes it neatly on a card the customer can read, and hands it over.
- The cook has an assistant standing in front of them. Every order goes through the assistant first.
- Before the cook starts, the assistant opens a fresh page in the order book.
- Then the cook does the work, writing everything on that page.
- Everything went well, so the assistant signs the page and it all counts.
- Another order comes in, and this time the cook drops a plate halfway through.
- The assistant tears out the page, so it's as if the half-finished order never happened.
- You arrive with boxes of kitchen gear, a stove kit and a fridge kit, but don't set anything up yourself.
- A setup crew opens each box and installs what's inside with sensible settings. A fridge kit means a working fridge.
- The crew also sets up the tools that go with the fridge, already plugged in.
- The stove kit means the kitchen opens its doors, ready for customers.
- If you bring your own fridge, the crew leaves theirs in the box. Your choice always wins.
๐งฉ Key questions
- In a big restaurant, who hires the staff and introduces them?
- The manager, so cooks just say what they need. The cooks never hire anyone; every worker the manager hires is a bean.
- On practice day the cashier gets a pretend card machine. Why does the cashier work the same way?
- Because the cashier only asks for "something that can charge a card". The manager can swap what the cashier gets.
- The cook drops a plate halfway through an order. What does the invisible assistant do?
- Tears out the page, as if the order never happened. The waiter doesn't even know the assistant is there.