# Exercise: Un-Pattern This

Take a corner of Summit Gym's code that a teammate made "flexible" for a future that never came, remove what doesn't earn its keep with every test green, and then add two features (a second gym and each instructor's own schedule) that are easy only once the code is simple.

Journeyman · C# · Java · Python · JavaScript · TypeScript · Updated November 17, 2026

By Gregor Dzierzon

Every other exercise in this course has added a pattern. This one takes patterns out. Summit Gym is opening a second gym, the instructors want their own schedules, and the code that prints the daily schedule was "made flexible" by a teammate who has since moved teams. Your job is to make it simple first, without changing what it prints, and then to add the two features, which turn out to be small once you can see the code.

## Before you start

You need one language set up, as in *Setup: VS Code and Your Language*, and to know how to run the tests, as in *Running the Exercise Tests*. The exercise is written in all five of the course's languages; pick the one you use.

## Get the exercise code

Open this lesson's GitHub repository, [github.com/ask-codey/exercise-dp-un-pattern-this](https://github.com/ask-codey/exercise-dp-un-pattern-this), also linked from the **Exercise** box beside the lesson. Clone it into your course folder. In a terminal, in that folder:

```bash
git clone https://github.com/ask-codey/exercise-dp-un-pattern-this.git
```

Git makes a folder, `exercise-dp-un-pattern-this`, with the exercise code inside.

The repository has a folder for each language: `csharp`, `java`, `python`, `javascript` and `typescript`. Each folder holds:

- **the schedule's code**, as the teammate left it: a `Gym` that keeps the day's classes and prints its schedule, and the classes it uses to do that (the repository's `README.md` names the files for each language);
- **the tests**, which you don't need to change;
- **a demo program** that prints two gyms' schedules for the day.

In VS Code, choose **File > Open Folder** and open **your language's folder**, not the whole repository.

## The ticket

> **From:** the owner, Summit Gym
>
> 1. **Summit Gym North opens next month.** The same system has to keep both gyms' daily schedules, side by side, each with its own classes.
> 2. **The instructors' app wants each instructor's own day.** It calls `scheduleFor("Omar")` and expects Omar's classes, in order, written the same way as the full schedule.
>
> **From:** the team lead
>
> Every comment in the schedule code says something "can be added later", and nothing ever was. Before you add anything, take out whatever isn't earning its keep. The day's schedule must look exactly the same afterward.

`scheduleFor` is already there, because the instructors' app calls it, but it gives back nothing yet.

## What to do

1. **Run the tests first.** Three pass: they're what the schedule does today, and your pins while you change it. Two fail: they're the ticket.
2. **Read the code, and for each class ask one question** from *Pattern Fever*: what change does this make easy, and is that change happening? Make a short list of what you'd take out, and why.
3. **Take them out one at a time**, running the tests after every step, the small steps of *Refactoring Toward a Pattern* run the other way. The three that pass must stay green the whole time. Deleting a file is a step too.
4. **Then add the two features.** Stop when all five tests are green and the demo prints what *When you're done* shows.

The README's *Stuck?* section names what to take out, if you want it. Try a few minutes without it first.

## Check your work

Each language has its own command, run in the terminal in your language's folder (**Terminal > New Terminal** in VS Code). The repository's `README.md` has the full list, including the one-time setup for Python (a virtual environment and pytest) and TypeScript (`npm install`).

| Language | Run the tests | Run the demo |
|---|---|---|
| C# | `dotnet test` | `dotnet run --project UnPatternThis` |
| Java | `./mvnw test` (`.\mvnw test` in PowerShell) | `java src/main/java/Demo.java` |
| Python | `python -m pytest` | `python demo.py` |
| JavaScript | `npm test` | `node demo.js` |
| TypeScript | `npm test` | `node demo.ts` |

A failing test's message starts with **Not yet:** for the ticket's work, or **Keep this working:** if a change broke something that worked, and says what it expected, for example *Not yet: Downtown's schedule has only its own yoga class.*

## Hints

- **Start with the demo.** It makes two gyms and prints Downtown's schedule, and Downtown shows North's class. Where are a gym's classes kept, and who else can reach them?
- **Count the jumps** from `schedule` to the line of text it prints. Each jump should be doing something.
- **Simpler first, features second.** If you add `scheduleFor` before you simplify, you'll write it twice.

## When you're done

All 5 tests are green, the schedule's code is short enough to read in one go, and the demo prints the same three lines in every language:

```text
Downtown: 7:00 Yoga with Priya, Studio A; 12:00 Spin with Omar, Bike room
North: 18:00 HIIT with Omar, Main floor
Omar at Downtown: 12:00 Spin with Omar, Bike room
```

Two gyms keep their own classes, and the instructors' feature is a few lines that read like the ticket.

## Submit your exercise

The exercise is how you finish this lesson. When your work is done, put it on GitHub in a repo of your own, then submit that repo's address here.

1. On GitHub, click **+**, then **New repository**. Name it (for example `exercise-dp-un-pattern-this`), choose **Public**, and click **Create repository**. Leave out the README: your folder already has one.
2. In a terminal in your exercise folder (Git Bash on Windows), send your work to your new repo. Point your copy at your own repo, then commit and push:

   ```bash
   git remote set-url origin https://github.com/your-name/exercise-dp-un-pattern-this.git
   git add .
   git commit -m "My solution"
   git push -u origin main
   ```

3. Paste your repo's address, such as `https://github.com/your-name/exercise-dp-un-pattern-this`, into **Submit your exercise** on this page. The site checks that the repo is public and holds your commits, and then the lesson is complete.

Changed something after you submitted? Push it, and submit again: your latest submission is the one that counts.

## So what

Taking a pattern out, safely, is as much a part of the job as putting one in. The tests kept the schedule exactly as it was while it shrank, and the features that were hard in the "flexible" version turned out to be a few lines in the simple one.

## Key terms

- [Over-Engineering](https://www.ask-codey.com/glossary/over-engineering)
- [YAGNI](https://www.ask-codey.com/glossary/yagni)
- [Refactoring](https://www.ask-codey.com/glossary/refactoring)

## Related

- [Pattern Fever: When a Pattern Makes Code Worse](https://www.ask-codey.com/lessons/dp-pattern-fever)
- [Refactoring Toward a Pattern, One Small Step at a Time](https://www.ask-codey.com/lessons/dp-refactoring-toward-a-pattern)
- [Pin It Down: Tests for Code You Didn't Write](https://www.ask-codey.com/lessons/dp-characterization-tests)

Source: https://www.ask-codey.com/lessons/exercise-dp-un-pattern-this
