YAGNI means “You Aren’t Gonna Need It.” Build functionality when it is needed, not because a future requirement seems possible. Every speculative feature or abstraction adds code that someone must understand and maintain. section 4.2
The practical default is to solve the current problem with the simplest suitable design. This can reduce complexity and make later changes easier. It does not mean refusing to think ahead; it means asking whether a proposed addition serves a real need or only a guess. section 4.2 section 4.1
Common signs that a design may be getting ahead of its needs include:
- Abstract classes or interfaces where a simple implementation would suffice. section 4.2
- Generic types or methods without a current use for their flexibility. section 4.2
- Features built for hypothetical users, or code unused by production. section 4.2
- Optimizations in code that does not significantly affect performance. section 4.2
Design for the product idea, not every imagined feature
An online ordering system that starts with a deliverCoffee method might add another method for coffee and food, then more methods as items change. A deliver method accepting a DeliveryList instead expresses the underlying idea—delivery—without implementing speculative ordering features. YAGNI need not force a design tied too narrowly to today’s first requirement. section 4.3
interface Delivery {
public void deliver(DeliveryList items);
}
class DeliveryList {
private List coffees;
// Other items can be added as needed
}
The Java interface takes a DeliveryList, so the delivery operation is not named after one item type. section 4.3
Use YAGNI as a default, not an absolute ban on preparation. Long-term architecture, anticipated user growth, and regulatory compliance can justify planning ahead. The choice is whether that preparation earns its ongoing maintenance cost. section 4.2




