Object Cases: Examples of objects

Last week I wrote that Claude made 69 tests and found two bugs based on a specification. But how do you make a consistent and complete specification of the business logic in a system?

I use a method I call Object Cases. It builds on Specification by Example and Behaviour Driven Development (the Given/When/Then format) and consists of three parts:

1. Objects. What data the system has and what it can do.

2. Examples. How the objects are used and changed.

3. Diagrams. The examples are illustrated so that a domain expert can judge them.

Behaviour driven development (BDD)

Here is a BDD example from a vocabulary app I have made. One of the business rules is that the app should repeat words until you have got them right three days in a row, and then wait a week. I have described this with an example:

Given 10 words: word1 … word10
And these attempts:
- word1: wrong+correct, wrong+correct, correct
- word2: wrong+correct, wrong+correct, correct
- word3: wrong+correct, correct, correct
- word4: wrong+correct, correct, correct
- word5: correct
When a new round starts on day 4
Then the app shows these words in random order: word1, word2, word6, word7, word8
And word3 and word4 will not be shown because they were mastered less than 7 days ago

In BDD, business users were supposed to write examples like this, which developers and testers could use directly.

The developers also had to write glue code that translates the text into runnable tests. This was rather cumbersome, but now you can get AI to write this glue code, as I have written about before.

An example of objects

But what if you skip the text and the glue code and write the example as ordinary code? If you describe the given, when and then steps with objects and functions that exist in the code itself, the example runs directly and you need neither a parser nor step definitions.

As code, the same example looks like this:

  example('A word mastered on day 3 is not reviewed before day 10', () => {
    given(
        StudyWord('word1', { attempts: 'wrong+correct, wrong+correct, correct' }),
        StudyWord('word2', { attempts: 'wrong+correct, wrong+correct, correct' }),
        StudyWord('word3', { attempts: 'wrong+correct, correct, correct' }),
        StudyWord('word4', { attempts: 'wrong+correct, correct, correct' }),
        StudyWord('word5', { attempts: 'correct' }),
        Words('word6', 'word7', 'word8', 'word9', 'word10')
    );
    when(newRound({ day: 4 }));
    then(
        Session({ cards: ['word1', 'word2', 'word6', 'word7', 'word8'], reviews: [] }),
        StudyWord('word3', { status: 'mastered', difficulty: 'easy', reviewDueDate: 'day 10', isDue: false }),
        StudyWord('word4', { isDue: false }),
    );
    note('word3 and word4 were mastered less than 7 days ago.');
});

But a business expert cannot write this!

In practice it was probably not business users who wrote the BDD examples, but developers. What matters is that the business can read and understand the examples.

But the code is much longer than the BDD example!

Yes, but you do not have to write the code yourself, you can do that with AI. What matters is that you understand it. When you work like this, why should AI write in a language that has to be parsed?

Visualisation

I agree that examples as code are less readable than BDD text. But there is something even easier to understand than text: Pictures.

I for one often use drawings on a whiteboard when I explain or discuss something. And when someone explains something complicated to me, I make a drawing in my head of what they say.

So I get the framework to draw an illustration of the example, and then I (or a business user) approve it.

An example of an example

Here is such an illustration of the example above. It visualises the following question: If a user has practised for 3 days, which words should the app show on day 4? This is a question to the business user.

Utgangspunktet

The answer is illustrated below. It is then the business’s job to check whether it is correct.

Ny runde på dag 4

On day 10 the mastered words are reviewed.

Ny runde på dag 10

These diagrams are not just a visualisation of a specification. They show the objects that actually run and whether they are as expected, not just passed or failed. That is why they show more detail than the specification does.

“Why is word5 not repeated?” you might ask. The answer is another business rule: It was mastered on the first attempt and is never repeated. It is questions like this I want to bring out with this method.

This was a very simple example. Will it scale?

I think so, but it needs to be verified. I have used this in two small projects. Larger projects will probably have to be visualised in another way.

But here is my experience from these projects:

  1. The vocabulary app has 55 such examples. I have changed the app many times without checking the AI-generated code. These tests make sure the functionality does not break, and they helped me find dead code that could be deleted. So the examples keep the model consistent.

  2. The system I wrote about last week has 114 examples. They describe the behaviour of the system and the rights of the different roles. The code has been through large refactorings without the behaviour breaking. And the declared domain model made it easy for Claude to make the tests.

And what is the alternative? A huge requirements specification as text? How do you know whether it is correct and complete? I have more faith in a runnable specification.

Summary

We use examples all the time when we explain.

Specification by Example and BDD formalise this with free text and a translation layer between text and code.

Object Cases describes the examples as domain objects, preferably right in the code as runnable tests. A framework (which AI can make fairly easily) visualises them. The expert does not read code, but looks at the diagrams and approves or corrects them. Then we get a precise, shared language for users and code, and we need no glue between specification and code.

AI needs structure, and this method gives it that.


© 2026 Object Generation AS