Version 1: It Works
Plan the bakery's app, build version 1, and handle the first change request: a new product every month.
Updated
Plan It, Build It
- Meet the Bakery App: Plan It, Build It (Apprentice): The first pass starts with a small app that works: a neighborhood bakery's ordering app, planned as a class diagram, built as version 1 in five languages, and then asked the question every pass starts with: what's likely to change?
A New Product Every Month
- Simple Factory: One Place That Says new (Apprentice): When the same if chain that picks a class is copied into several places, a new product means editing all of them, and one is always forgotten; a simple factory moves that decision into one function, so a new product is one new class and one new line.
- Factories the Modern Way: A Dictionary of Functions (Apprentice): A factory's if chain still grows by one line a month and gets edited by everyone; a dictionary from each product's name to a function that makes it lets a new product be added in one line, from anywhere, without touching the factory.
Only One of Something
- Singleton: Only One, Ever (Apprentice): When two parts of an app each make their own copy of something the whole app should share, such as the shop's settings, they quietly disagree; the Singleton pattern makes a class allow only one object and gives everyone the same one.
- Why Singleton Is Usually a Trap (Journeyman): A Singleton fixes two copies that disagree, but it hides what a class needs and lets tests change each other's results; making one object at the start of the app and handing it in keeps one shared object without either problem.
Exercise: The Bakery Order Counter
- Exercise: The Bakery Order Counter (Journeyman): Take a ticket from Sunrise Bakery's owner: pies launch Monday and a second shop opens with its own tax rate. Change the working order code so new products are added from outside and each shop charges its own tax, with the tests green throughout.