الانتقال إلى المحتوى
Software Architectureمبادئ التصميم· 8 دقائق للقراءة

YAGNI Explained: The Real Cost of Designing for Imagined Requirements

An extension point for a future that hasn't arrived costs you to build, delays what's needed now, and slows every change until it's used or removed.

ReadIn

مقال كل يوم يفرق معاك

21 نوفمبر 2026
  • كاتب موثّق
محتويات المقال

The notifications module has an INotificationChannel interface, a ChannelRegistry, a channel name in configuration and one EmailChannel, because two years ago someone said "we'll add SMS and push later". There is still only email. Then product asks for something nobody predicted: a daily digest instead of one email per event. The design assumed the thing that would vary was the channel. What actually varies is timing, and a SendAsync call per event is in the way. Now the team has to work around the extension point before it can build the feature.

The common misconception

The belief: good design means anticipating requirements. If you know SMS is coming, add the interface, the registry and the configuration now, while you're in the code, so the future change is just a new class.

It's an honest instinct. For years design advice pushed in that direction: Fowler notes that in the late 1990s there was a lot of advice about "adding elements to an architecture in order to increase flexibility for future requirements." It also feels cheaper. Fowler says the common reason people build presumptive features is that "they think it will be cheaper to build it now rather than build it later." And sometimes the guess is right.

The half-truth: code that is easy to extend is good. But code built for imagined extensions is usually harder to extend in the direction that actually arrives.

What actually happens

YAGNI targets presumptive features

The phrase comes from Extreme Programming: Fowler traces it to a conversation in which Kent Beck answered each capability Chet Hendrickson proposed with "you aren't going to need it". Ron Jeffries put the rule plainly in 1998: "Always implement things when you actually need them, never when you just foresee that you need them." Fowler calls code that supports a feature nobody can use yet a , and says not to build it.

Four costs of building ahead

Fowler breaks the bill down:

  • Cost of build: the analysis, code and tests for something that may never be used.
  • Cost of delay: the feature you didn't ship while you built the presumptive one. This one applies even when the guess is right.
  • Cost of carry: the extra complexity makes every other change harder to read, modify and debug, until the feature is used or removed.
  • Cost of repair: the right feature built wrong, because by the time it's needed you know more than you did when you wrote it.

And the guess is often wrong. Fowler cites work by Kohavi and colleagues who found that, even with careful up-front analysis, only about a third of the features they studied at Microsoft improved the metrics they were designed to improve.

Abstractions are presumptive too

Fowler says the same argument applies to abstractions added for future flexibility: you may not need the other variations, and if you do, "your current ideas of what abstractions you'll need will not match what you learn when you do actually need them." He doesn't ban abstractions; he says any abstraction "that makes it harder to understand the code for current requirements is presumed guilty." That's the digest story: the extension point bet on the wrong axis of change.

What YAGNI doesn't say

YAGNI doesn't apply to work that makes code easier to change: refactoring, self-testing code and continuous delivery are what make it safe. Fowler is blunt: "Yagni is not a justification for neglecting the health of your code base." It also doesn't forbid cheap foresight. If a small choice adds no real complexity but makes a later change much easier, like keeping error messages in a lookup table instead of inline strings, there's no reason to invoke YAGNI. His Design Stamina Hypothesis makes the same bet from the other side: effort spent on design lets a project go faster for longer.

The fix: build for today, keep it easy to change

C#
// Built for "SMS and push later". Two years on, email is the only channel.public interface INotificationChannel{    string Name { get; }    Task SendAsync(Notification n, CancellationToken ct);}public sealed class ChannelRegistry(IEnumerable<INotificationChannel> all){    public INotificationChannel Get(string name) =>        all.Single(c => c.Name == name);}public sealed class Notifier(ChannelRegistry registry, string channelName){    public Task NotifyAsync(Notification n, CancellationToken ct) =>        registry.Get(channelName).SendAsync(n, ct);}public sealed class EmailChannel(IEmailSender email) : INotificationChannel{    public string Name => "email";    public Task SendAsync(Notification n, CancellationToken ct) =>        email.SendAsync(n.To, n.Subject, n.Body, ct);}

The right version still depends on an IEmailSender interface: the email provider is an external system and the tests need to replace it today, so that abstraction serves a current need. What's gone is the machinery for channels that don't exist, and with it the three hops a reader had to follow to learn that Notifier sends an email. When the digest request arrives, the change happens in one small class that says exactly what it does. If SMS ever arrives, the refactoring is an extracted interface and a new class, and it's designed around the real requirement: per-user preferences, fallbacks, or whatever product actually asks for.

MythReality
Good design anticipates future requirementsGood design keeps code easy to change; Fowler: the guess is likely to be wrong
Building it now is cheaper than laterFowler: compare it against the cost of delay and the odds the feature is never needed
Extension points make code more flexibleAn unused extension point adds complexity and often bets on the wrong axis of change
YAGNI means skipping designYAGNI requires malleable code: refactoring and tests are not presumptive features
YAGNI forbids any thought about the futureCheap foresight that adds no real complexity, like message lookup tables, is fine

How to apply it in your project

  1. List extension points with one implementationInterfaces with a single implementation that tests don't replace, registries, factories and strategy maps with one entry, configuration switches nobody changes.
  2. Ask what each one costs todayHow much harder does it make the current code to read and change? Which features did it slow down? Has the predicted variation arrived?
  3. Inline the ones that don't payCollapse the indirection into the concrete code, with tests protecting the behavior. Keep abstractions that serve a current need, like replacing an external system in tests.
  4. Spend the savings on changeabilityPut the time into tests, refactoring and a fast deployment pipeline, so that when a real requirement arrives, adding the extension point is an easy change.

Key takeaways

  • YAGNI says to build capabilities, and the abstractions behind them, when a real requirement needs them.
  • Building ahead has four costs: build, delay, carry and repair; the delay and the carry apply even when the guess is right.
  • Speculative abstractions often bet on the wrong axis of change and get in the way of the change that really comes.
  • YAGNI doesn't apply to refactoring, tests or delivery practices; it depends on them.
  • Cheap foresight that adds no real complexity is fine; complexity for an imagined future is presumed guilty.

📚 المصادر

  1. Yagni — Martin Fowler
  2. You're NOT gonna need it! — Ron Jeffries (1998)
  3. Beck Design Rules — Martin Fowler
  4. Design Stamina Hypothesis — Martin Fowler

التعليقات (0)