Before writing any C#, try to tell a robot how to make a cheese sandwich. The exercise exposes the assumptions hidden in ordinary instructions, and those hidden assumptions are the same things a class has to name: what exists, what condition each thing is in, and which actions change that condition. Blessed Emmanuel John chidera describes this exercise in a DEV Community post dated September 19, 2026, written as a mentoring session with an apprentice named John. The method is a teaching anecdote, and the sections below follow its sequence, from vague instructions to a small C# class.
The instruction that looked finished
The exercise starts with a robot in a kitchen. It has bread, butter, a knife, a plate, and cheese, and the learner must write step-by-step instructions to assemble a cheese sandwich. In the original post, the first attempt named the objects correctly and then gave directions such as “take,” followed by ingredients combined with plus signs. To a person, that reads as a recipe. To a robot, it leaves too much open.
As an Amazon Associate I earn from qualifying purchases.
Where the first draft breaks
A robot cannot safely infer the missing details. An illustrative version of the same kind of instruction, with questions a literal machine would need answered, looks like this:
PC Slower Than It Used to Be?
A free scan shows the junk files, broken settings and background clutter dragging Windows down - then fixes them in one click.Free scan · Windows 10 & 11Outdated Drivers Are Slowing You Down
One free scan finds every outdated or missing driver and matches the right update for your exact hardware.Free scan · exact hardware match- Take what: the whole loaf, a slice, or the bag?
- Take from where, and how is it held?
- Is the knife clean, and is it already holding butter?
- Does the butter go on before the cheese or after it?
- Is the plate empty, and which slice is the base?
The plus sign is a deliberately weak model of assembly. It says that the ingredients are combined but not in what order, with which actions, or with what result. This is a criticism of the sandwich model, not of addition. In arithmetic, “2 + 3” is a complete expression. A physical assembly needs operations and an order of operations.
#1 Best Overall
Naming entities, tools, a container, and operations
The revised model sorts the parts by role. The original post names the operations SCOOP, SPREAD, and LAY. Once each role is explicit, the instructions can say which thing acts and which thing is acted on.
| Role | Item in the exercise | What the model makes explicit |
|---|---|---|
| Entities | Bread, butter, cheese | The things the task is about |
| Tool | Knife | The thing used to act on an entity |
| Container | Plate | The place where the work happens |
| Operations | SCOOP, SPREAD, LAY | The named actions that can be performed |
An illustrative rewrite in that spirit reads:
- SCOOP butter from the tub onto the knife.
- SPREAD the butter from the knife onto one slice of bread on the plate.
- LAY one slice of cheese onto the buttered slice.
This version still does not describe a complete robotics specification. It makes inputs and actions visible, which is the purpose of the exercise.
State: the same bread in a different condition
The bridge to object-oriented thinking comes from one change. Plain bread becomes buttered bread after SPREAD runs. The slice is still the same slice. Only its condition has changed.
Rank #2
That condition is the entity’s state. An operation can do one of two things: change the state, as SPREAD does, or only inspect it. The next example separates those two cases.
Commands and queries: change it or read it
The original post then uses a bank account. It begins with a $5,000 balance, deposits $1,000, withdraws $500, and then checks the balance. The check reports a value and leaves the account as it was. The post calls this distinction Command-Query Separation.
| Step | Kind of operation | Balance after the step | What the step returns |
|---|---|---|---|
| Account opened with $5,000 | Setup | $5,000 | Nothing |
| Deposit $1,000 | Command (changes state) | $6,000 | Nothing |
| Withdraw $500 | Command (changes state) | $5,500 | Nothing |
| Check balance | Query (reads state) | $5,500, unchanged | The current balance |
The figures need a correction. The original post reports that the check returns $4,500, but the amounts it gives add up to $5,500. The table uses the stated amounts. The lesson does not depend on the arithmetic: the check reads the balance and changes nothing. Readers who copy the example should use the amounts they choose and recompute the result.
The rule described here is a convention the example follows. C# does not enforce it. A method that returns a value can also change state, and a method that changes state can also return a value. The point of the separation is to make a method’s purpose easy to read.
What’s actually slowing this PC down?
Pick the symptom - the matching free tool is one click away.
From one car to a class
The post then asks how to represent 100 cars, each with a speed, a fuel level, and an engine state, without rewriting the same behavior for every car. The answer is a shared template. The template is the class. Each car built from it is an instance, with its own values.
Microsoft’s C# documentation states the idea in a sentence that fits the car example closely: “In C#, the definition of a type—a class, struct, or record—is like a blueprint that specifies what the type can do.” The sentence comes from Microsoft Learn’s C# documentation, not from a named author. The class tutorial is at Microsoft Learn: Classes and objects tutorial – C#.
Rank #4
The car is an entry point, not a rule. Not every noun in a program should become a class. The useful question is whether a thing has state and operations that belong together.
Mapping the model onto C#
The original post connects each idea from the sandwich and car examples to a C# member. Microsoft Learn describes the same parts: a class has members such as properties and methods, and a constructor initializes a new instance.
Do these 3 things before closing this tab:
1Clear out junk files and repair common Windows errors2Scan for outdated or missing drivers - takes under a minute3Repair Windows errors before they cause bigger problems| Model idea | C# member | Car example |
|---|---|---|
| Template for many things | class Car |
The shared car definition |
| One thing built from the template | new Car(...) |
One particular car |
| Condition that persists | Properties such as Speed, Fuel, IsEngineRunning |
The car’s current speed, fuel, and engine state |
| Starting values | Constructor | A new car begins with the engine off and speed zero |
| Operation that changes state | Methods such as StartEngine and Accelerate |
Turning the engine on, or increasing speed |
| Query that reads state | Method such as CheckSpeed |
Reporting the speed without changing it |
| Rule preventing invalid state | Condition inside a method | Speed changes only when the engine is running |
A minimal class that follows the model
The following version follows the members the original post describes. It is illustrative and has not been tested or hardened for production. In this sample, Fuel is stored but never used up.
Best Value
public class Car
{
public int Speed { get; private set; }
public double Fuel { get; private set; }
public bool IsEngineRunning { get; private set; }
public Car(double fuel)
{
Speed = 0;
Fuel = fuel;
IsEngineRunning = false;
}
public void StartEngine()
{
IsEngineRunning = true;
}
public void Accelerate(int amount)
{
if (!IsEngineRunning)
return;
Speed += amount;
}
public int CheckSpeed()
{
return Speed;
}
}
Each part of the sketch maps back to the model:
- The constructor sets the starting condition of every new car.
StartEngineis a command: it changesIsEngineRunning.Accelerateis a command with a guard. If the engine is off, the method returns before changing anything.CheckSpeedis a query: it returnsSpeedand leaves it alone.
Two instances show how the values stay separate:
Car first = new Car(40.0);
Car second = new Car(25.5);
first.StartEngine();
first.Accelerate(20);
second.Accelerate(30); // ignored: this engine is not running
Console.WriteLine(first.CheckSpeed()); // 20
Console.WriteLine(second.CheckSpeed()); // 0
The two cars share one definition, but each keeps its own speed and engine state.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Four questions to ask before you write code
The original post closes the exercise with prompts for planning a class before typing it:
- What entities exist in this problem?
- What state does each entity hold?
- For each operation, does it change state or only read it?
- What rules prevent invalid state, such as accelerating with the engine off?
What the exercise does and does not show
- Evidence: The method is an author-reported teaching anecdote from a mentorship session. The original post reports no research design, measured outcomes, or comparison showing that the approach improves learning, and this article cannot add such evidence.
- Opinion: The post’s criticism of beginner tutorials and its “tutorial hell” framing are the author’s views, not measured findings.
- Metaphor: The plate is useful for separating an object from the context in which it is used. The post’s comparison to execution environments, memory allocation, and memory leaks is an analogy, not a technical explanation of how memory is managed.
- Narrow scope: The sandwich covers entities, state, operations, and classes. It does not cover all of object-oriented design. Microsoft’s Object-Oriented programming (C#) tutorial outlines abstraction, encapsulation, inheritance, and polymorphism as separate topics.
- Naming: Command-Query Separation is an established idea, and the original post presents it through its own bank example. The post does not claim the apprentice discovered it independently.
The original post is at We Reinvented OOP by Making a Sandwich (Before Writing Any Code).
Try the exercise yourself
The original post ends with a question worth answering in your own words: how would you explain variables and assignment to a complete beginner without using the word “variable”? Try answering it as a sandwich-style list of steps, naming each thing, what it holds, and what each step does to it.
Quick Recap
Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.




