ThisCalculator

Everyday

OOP Reinvented: Sandwich Before Code?

Updated · Standard formula, shown below

Layers per minute 0.20
Total prep seconds
900 s
Result
Prep time
15 min
You entered
Number of layers
3
You entered

No, object-oriented programming was not reinvented by making a sandwich before writing code. The phrase is a playful metaphor for a design-first approach, not a literal historical event. This article explains what the metaphor actually means, where it comes from, and how it relates to real software design practices.

Formula

The calculator above is a playful way to think about the sandwich metaphor: it computes how many layers of a sandwich you can prepare per minute, given a prep time and number of layers. The formula is:

Layers per minute = Number of layers ÷ Prep time (minutes)

Where:

  • Prep time (t) – the total time to assemble the sandwich, in minutes.
  • Number of layers (d) – the count of distinct layers (bread, filling, etc.).

The second output, total prep seconds, is simply prep time multiplied by 60.

Worked Example

Using the default values: prep time = 15 minutes, layers = 3.

  1. Layers per minute = 3 ÷ 15 = 0.20 layers/min
  2. Total prep seconds = 15 × 60 = 900 seconds

The calculator shows 0.20 layers/min and 900 seconds. This matches the formula exactly.

What the Sandwich Metaphor Really Means

The phrase “we reinvented OOP by making a sandwich before writing any code” is a tongue-in-cheek way to describe a design methodology that emphasizes planning and structure before implementation. It is not a factual claim about the history of OOP; rather, it is a teaching tool used in some programming courses and blog posts to illustrate the idea of decomposition.

In object-oriented programming, you break a problem into objects (like ingredients) and define how they interact (like assembling a sandwich). The metaphor suggests that if you can describe the steps of making a sandwich in a structured way, you can apply the same thinking to code.

Background: Where Did the Metaphor Come From?

The exact origin of the sandwich metaphor in programming is unclear, but it likely emerged from educational contexts that used everyday analogies to explain abstract concepts. Similar analogies exist for other paradigms: a recipe for procedural programming, a blueprint for architectural design, or a team roster for object-oriented roles.

The metaphor gained traction in online developer communities because it is memorable and relatable. It is not tied to any specific programming language or framework; it is a general conceptual tool.

How It Relates to OOP Principles

Object-oriented programming is built on four main principles:

  • Encapsulation – hiding internal details, like wrapping ingredients in bread.
  • Abstraction – focusing on what matters, not the exact ingredients.
  • Inheritance – reusing a base recipe, like a BLT inheriting from a sandwich class.
  • Polymorphism – different fillings can be used interchangeably.

The sandwich metaphor helps illustrate these principles because a sandwich is a composition of parts that can be modified without changing the whole. For example, you can swap turkey for ham (polymorphism) without rewriting the entire sandwich.

Common Misconceptions

One common misconception is that the metaphor implies you should plan every detail before coding, which is not always practical. Agile methodologies advocate for iterative development, where you build a small part, test it, and adjust. The sandwich metaphor is better suited for understanding OOP concepts than for prescribing a strict workflow.

Another misconception is that OOP is the only “correct” way to program. In reality, functional and procedural paradigms have their own strengths. The sandwich metaphor is just one way to think about problem-solving.

Practical Takeaways for Developers

If you are learning OOP, the sandwich metaphor can help you:

  • Identify objects in a problem (e.g., Customer, Order, Product).
  • Define their responsibilities (e.g., a Customer places an Order).
  • Think about how objects communicate (e.g., methods and messages).

However, do not over-plan. Start with a rough sketch, write a small prototype, and refine. The metaphor is a starting point, not a rigid rule.

Frequently Asked Questions

Is the sandwich metaphor a real historical event?

No, it is a fictional analogy. There is no record of anyone reinventing OOP while making a sandwich. It is a creative way to explain design concepts.

Does this mean OOP is about food?

No, OOP is a programming paradigm. The sandwich is just an analogy to make the concepts more accessible. You do not need culinary skills to write object-oriented code.

Can I use this metaphor in a job interview?

Yes, if you explain it as a way to think about decomposition and design. It shows you can communicate complex ideas with simple examples, which is a valuable skill.

Is planning before coding always better?

Not always. Some projects benefit from rapid prototyping. The metaphor encourages thought, but agile methods often favor small, iterative steps over exhaustive upfront design.

Are there other metaphors for OOP?

Yes, common ones include a car (engine, wheels, body) or a zoo (animals, habitats). The key is to find a metaphor that resonates with your audience.

Related

Formula used
in t | Prep time | min | 15 | 0
in d | Number of layers | - | 3 | 1
out layers_per_min | Layers per minute | - | d / t | 2
out total_time_seconds | Total prep seconds | s | t * 60 | 0

Each line is one input (in, sel, list) or one result (out: label, unit, formula, decimals). How the calculators work

Method: the standard formula for this calculation, rounded as each result states. See how the calculators work or report an error.