# Meet the Bakery App: Plan It, Build It

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?

Apprentice · OOP · Software Development · Updated November 17, 2026

By Gregor Dzierzon

## After this lesson you can

- Plan a small app's first version as a class diagram of its classes and how they connect
- Name the parts of an app most likely to change, and keep each one easy to find

## Key takeaways

- Before writing code, name the things the app deals with (a cake, an order) and draw them as a class diagram: boxes for classes, arrows for how they connect.
- Version 1 only has to work. It doesn't need a single design pattern.
- The most useful planning question is "what's likely to change?": products, deals, who hears about an order, and the checkout steps will, while "an order has products and a total" won't.
- Every pattern in this pass comes from that list of changes, met one at a time, not from a catalog of patterns.

Every app you'll work on started small, and it worked. Then someone asked for a change, and another, and how the code handled the first few decided whether the tenth was easy or miserable. This pass follows one small app through that story: a neighborhood bakery's ordering app. This lesson plans it and builds version 1. The rest of the pass takes the owner's change requests one at a time.

## What the app does

Sunrise Bakery sells three things: cakes ($30), boxes of six cupcakes ($12) and cookie boxes ($8). A customer picks what they want on a tablet at the counter, the app adds it up, and the receipt prints. That's all version 1 has to do.

## Plan it: a class diagram first

Before any code, list the things the app deals with. They're nouns in the story: a **cake**, **cupcakes**, a **cookie box**, and an **order** that holds them. Each one becomes a class.

The three things for sale have something in common: each has a name and a price. So they all keep one promise, *Product*: "I can tell you my name and my price." In C#, Java and TypeScript that promise is an interface. Python and JavaScript have no interface keyword; any object with a name and a price will do.

A **class diagram** draws this as boxes and arrows. Each box is a class with its fields and methods. A dashed arrow with a hollow head means "keeps this promise", and a line from Order to Product means "an order holds products".

![A class diagram of the bakery app: a Product box (name, price) at the top, with three dashed arrows pointing up to it from Cake (Cake, $30), Cupcakes (Cupcakes, $12) and Cookie box (Cookie box, $8); beside it an Order box (products, add, total) with a line to Product labeled "holds 0 or more"](https://fsdtrainingmedia.blob.core.windows.net/public/images/2026/11/8a9daed4993d4896bd35a05ce62aeaa2.webp)

Drawing first takes five minutes and saves an hour. It shows what you're building, and it gives you words to ask the owner about before any code exists.

## Build version 1

Here is the whole app. `takeOrder` gets what the customer tapped, as words like `"cake"`, and turns each word into a product:

```csharp
Order order = TakeOrder(new List<string> { "cake", "cupcakes", "cookies" });
foreach (IProduct product in order.Products)
{
    Console.WriteLine($"{product.Name}: ${product.Price}");
}
Console.WriteLine($"Total: ${order.Total()}");

Order TakeOrder(List<string> kinds)
{
    Order order = new Order();
    foreach (string kind in kinds)
    {
        if (kind == "cake")
        {
            order.Add(new Cake());
        }
        else if (kind == "cupcakes")
        {
            order.Add(new Cupcakes());
        }
        else if (kind == "cookies")
        {
            order.Add(new CookieBox());
        }
    }
    return order;
}

interface IProduct
{
    string Name { get; }
    int Price { get; }
}

class Cake : IProduct
{
    public string Name => "Cake";
    public int Price => 30;
}

class Cupcakes : IProduct
{
    public string Name => "Cupcakes";
    public int Price => 12;
}

class CookieBox : IProduct
{
    public string Name => "Cookie box";
    public int Price => 8;
}

class Order
{
    public List<IProduct> Products { get; } = new List<IProduct>();

    public void Add(IProduct product)
    {
        Products.Add(product);
    }

    public int Total()
    {
        int total = 0;
        foreach (IProduct product in Products)
        {
            total += product.Price;
        }
        return total;
    }
}
```

```text
Cake: $30
Cupcakes: $12
Cookie box: $8
Total: $50
```

```java
interface Product {
    String name();
    int price();
}

class Cake implements Product {
    public String name() { return "Cake"; }
    public int price() { return 30; }
}

class Cupcakes implements Product {
    public String name() { return "Cupcakes"; }
    public int price() { return 12; }
}

class CookieBox implements Product {
    public String name() { return "Cookie box"; }
    public int price() { return 8; }
}

class Order {
    List<Product> products = new ArrayList<>();

    void add(Product product) {
        products.add(product);
    }

    int total() {
        int total = 0;
        for (Product product : products) {
            total += product.price();
        }
        return total;
    }
}

Order takeOrder(List<String> kinds) {
    Order order = new Order();
    for (String kind : kinds) {
        if (kind.equals("cake")) {
            order.add(new Cake());
        } else if (kind.equals("cupcakes")) {
            order.add(new Cupcakes());
        } else if (kind.equals("cookies")) {
            order.add(new CookieBox());
        }
    }
    return order;
}

void main() {
    Order order = takeOrder(List.of("cake", "cupcakes", "cookies"));
    for (Product product : order.products) {
        IO.println(product.name() + ": $" + product.price());
    }
    IO.println("Total: $" + order.total());
}
```

```text
Cake: $30
Cupcakes: $12
Cookie box: $8
Total: $50
```

```python
class Cake:
    name = "Cake"
    price = 30


class Cupcakes:
    name = "Cupcakes"
    price = 12


class CookieBox:
    name = "Cookie box"
    price = 8


class Order:
    def __init__(self):
        self.products = []

    def add(self, product):
        self.products.append(product)

    def total(self):
        total = 0
        for product in self.products:
            total += product.price
        return total


def take_order(kinds):
    order = Order()
    for kind in kinds:
        if kind == "cake":
            order.add(Cake())
        elif kind == "cupcakes":
            order.add(Cupcakes())
        elif kind == "cookies":
            order.add(CookieBox())
    return order


order = take_order(["cake", "cupcakes", "cookies"])
for product in order.products:
    print(f"{product.name}: ${product.price}")
print(f"Total: ${order.total()}")
```

```text
Cake: $30
Cupcakes: $12
Cookie box: $8
Total: $50
```

```javascript
class Cake {
  name = "Cake";
  price = 30;
}

class Cupcakes {
  name = "Cupcakes";
  price = 12;
}

class CookieBox {
  name = "Cookie box";
  price = 8;
}

class Order {
  products = [];

  add(product) {
    this.products.push(product);
  }

  total() {
    let total = 0;
    for (const product of this.products) {
      total += product.price;
    }
    return total;
  }
}

function takeOrder(kinds) {
  const order = new Order();
  for (const kind of kinds) {
    if (kind === "cake") {
      order.add(new Cake());
    } else if (kind === "cupcakes") {
      order.add(new Cupcakes());
    } else if (kind === "cookies") {
      order.add(new CookieBox());
    }
  }
  return order;
}

const order = takeOrder(["cake", "cupcakes", "cookies"]);
for (const product of order.products) {
  console.log(`${product.name}: $${product.price}`);
}
console.log(`Total: $${order.total()}`);
```

```text
Cake: $30
Cupcakes: $12
Cookie box: $8
Total: $50
```

```typescript
interface Product {
  name: string;
  price: number;
}

class Cake implements Product {
  name = "Cake";
  price = 30;
}

class Cupcakes implements Product {
  name = "Cupcakes";
  price = 12;
}

class CookieBox implements Product {
  name = "Cookie box";
  price = 8;
}

class Order {
  products: Product[] = [];

  add(product: Product): void {
    this.products.push(product);
  }

  total(): number {
    let total = 0;
    for (const product of this.products) {
      total += product.price;
    }
    return total;
  }
}

function takeOrder(kinds: string[]): Order {
  const order = new Order();
  for (const kind of kinds) {
    if (kind === "cake") {
      order.add(new Cake());
    } else if (kind === "cupcakes") {
      order.add(new Cupcakes());
    } else if (kind === "cookies") {
      order.add(new CookieBox());
    }
  }
  return order;
}

const order = takeOrder(["cake", "cupcakes", "cookies"]);
for (const product of order.products) {
  console.log(`${product.name}: $${product.price}`);
}
console.log(`Total: $${order.total()}`);
```

```text
Cake: $30
Cupcakes: $12
Cookie box: $8
Total: $50
```

It works, and that's the point of version 1. There isn't a design pattern in it, and it doesn't need one yet. Code that works and is easy to read is a fine place to start.

**Try it.** Add a second cake to the order and run it again. The total should be $80.

## What's likely to change?

Here is the question every pass in this course starts with. Before the owner asks for anything, ask: **which parts of this app are likely to change, and which aren't?** You don't need to guess well. You need to ask the people who run the business, and listen.

![A bakery's chalkboard behind the counter with the owner's wish list written on it in chalk: "New product every month", "This week's deal", "Tell the kitchen about new orders", "One button to check out"](https://fsdtrainingmedia.blob.core.windows.net/public/images/2026/11/71aa62e1d0fb436a9cc39b2fddc7dd39.webp)

Sunrise Bakery's owner has a list already:

| Likely to change | Why | Where it lives in version 1 |
|---|---|---|
| The products | A new one every month: pies are next | the `if` chain in `takeOrder` |
| The deals | A new one every week | nowhere yet |
| Who hears about an order | The kitchen now, a delivery driver later | nowhere yet |
| The steps of checking out | Payment, stock, the receipt, the kitchen | nowhere yet |

And some things almost never change: an order holds products, and its total is their prices added up. Those parts can stay simple.

The parts that will change are the ones to keep **easy to find**, each in one place, so a change touches one spot instead of five. That's the idea behind **encapsulation**, applied to whole parts of an app: put each thing that changes behind its own wall, and the rest of the code doesn't have to care.

## Where the patterns come from

Each row of that list will turn into a problem in this pass, and each problem into a fix that teams have found so often that it has a name: a **design pattern**. You'll meet the problem first, try the plain fixes, and learn the name last. That's the order it happened in real life: teams kept solving the same problems the same way, and someone wrote the solutions down.

The first row is first: pies arrive next month, and `takeOrder` is about to get a fourth `else if`.

## Check yourself

2 questions to try on the lesson page.

## So what

A class diagram and the question "what's likely to change?" are two of the most useful habits in software design, and they cost nothing but a few minutes before you write code. Every pass in this course starts with them.

## Key terms

- [UML Class Diagram](https://www.ask-codey.com/glossary/uml-class-diagram)
- [Design Pattern](https://www.ask-codey.com/glossary/design-pattern)
- [Encapsulation](https://www.ask-codey.com/glossary/encapsulation-oop)

## Cheat sheets

- [Meet the Bakery App: Plan It, Build It](https://www.ask-codey.com/cheat-sheets/dp-bakery-version-1-cheat-sheet)

Source: https://www.ask-codey.com/lessons/dp-bakery-version-1
