Topic 3 of 6 · 4 min read
Over-engineering and needless abstraction
Goal: Judge whether an abstraction in an AI-written change earns its cost and propose the simpler version.
An abstraction earns its place only when it removes real, present duplication or hides real, present complexity; anything built for a future nobody asked for is a cost with no return. Agents are good at producing the structure of a large system, so small tasks often come back wearing a lot of it.
Check yourself · 1 of 3
An agent adds an interface, a factory and a config object to send one email. What is the best question to ask?
Why it matters
You asked for a function that sends one email. The agent returns an EmailProvider interface, a factory, a config object with five options and a retry decorator. It looks professional. Now a reader must open four files to learn that it calls one API. Every layer is code to test, to keep in sync and to explain. Martin Fowler calls the habit of building for presumed needs "Yagni": you aren't gonna need it.
Signs of over-engineering
- One implementation behind an interface. If there is exactly one
PaymentGatewayclass and no second planned, the interface is noise. - A factory or builder for an object made in one place.
- Options nobody sets. Config flags, strategy parameters and plugin hooks with a single caller.
- Defensive checks for impossible states. Null checks on values the types guarantee,
try/catcharound code that cannot throw. - Wrappers that only forward. A class whose methods each call one method of another class.
- Generic names for specific jobs.
DataProcessorManagerfor something that parses one CSV.
How to ask for the simpler version
Be direct in the prompt: "Write the simplest version that works. No new classes, interfaces or config. One function in this file." Say what is out of scope. If a layer is truly needed later, you can add it when the second case appears; the cost of adding then is usually small.
Before and after
// Agent version: 3 files
interface Notifier { send(to: string, body: string): Promise<void> }
class EmailNotifier implements Notifier { /* ... */ }
export const notifierFactory = (cfg: NotifierConfig): Notifier => new EmailNotifier(cfg);
// Reviewed version: 1 function
export async function sendReceipt(to: string, body: string) {
await mailer.send({ to, subject: "Your receipt", text: body });
}
What goes wrong
- Cutting a real seam. A boundary around a payment API or a clock can be justified because it makes tests possible. Ask what the layer buys today.
- Removing needed checks. Validation at a system edge, such as user input, is not over-engineering.
- Accepting it because it looks senior. Complexity is not quality.
Examples
Config nobody sets
def fetch(url, timeout=10, retries=3, backoff=2.0, strategy="exponential", hooks=None):
...
Every caller uses the defaults. Strategy and hooks have no second value. Reduce it to fetch(url) with one constant, and add parameters when a caller needs them.
A justified boundary
A new Clock interface wraps Date.now(). It looks like needless abstraction, but the billing tests need to fix the time. The layer buys testability today, so keep it.
Key points
- An abstraction must remove present duplication or hide present complexity; a presumed future need does not count.
- One implementation behind an interface, or a factory for one call site, is usually noise.
- Defensive checks for states the types already rule out add reading cost and hide real errors.
- Prompt for the simplest version: name the file, ban new classes and config, and state what is out of scope.
- Keep seams that make real testing possible, and keep validation at system edges.
Common mistakes
- Approving structure because it looks professional or senior.
- Asking for "clean code" without saying "simplest version, one function".
- Removing input validation at a system edge as if it were a needless defensive check.
- Keeping an interface with one implementation "for flexibility".
Check yourself · 2 of 3
Which request is most likely to get a simple result from a coding agent?
Check yourself · 3 of 3
Which of these defensive checks is justified, not over-engineering?
Practice items, not counted towards your mastery.
Start here
- AI Copilot Code Quality: 2025 research (GitClear) (opens in a new tab)ArticleFree
An analysis of how code churn, copy-pasted lines and moved code changed as AI assistants spread.
- Refactoring (Martin Fowler) (opens in a new tab)BookFree
The catalogue of small behaviour-preserving steps and the reasoning behind doing them one at a time.
- Is High Quality Software Worth the Cost? (martinfowler.com) (opens in a new tab)ArticleFree
Why internal quality pays back through faster feature delivery, the case for caring about maintainability.
More for this topic
- Yagni (martinfowler.com) (opens in a new tab)ArticleFree
Why building for a presumed future need usually costs more than it saves.