Back to Catalog
Dry Yagni
principles
You Aren't Gonna Need It (YAGNI)
Don't implement functionality until you actually need it.
Intent & Description
'
🎯 Intent
Avoid adding features or abstractions that you think you might need in the future. Only implement what is currently required.
📋 Context
You’re adding “just in case” features, creating complex abstractions for hypothetical future scenarios, or building flexibility for requirements that haven’t been specified. This adds complexity and maintenance burden without delivering value.
💡 Solution
Focus on current requirements. Build the simplest thing that works. Refactor when new requirements emerge rather than anticipating them prematurely.'
Real-world Use Case
Use when you’re tempted to add “future-proof” features, when you’re creating complex abstractions for hypothetical scenarios, or when you’re over-engineering for flexibility.
📌 TL;DR
Build what you need now, not what you might need later. Simpler code, faster development, avoid waste. Refactor when requirements change.
Advantages
- Simpler, focused code
- Faster development cycles
- Reduced maintenance burden
- Avoids waste on unused features
Disadvantages
- May require refactoring later
- Can’t anticipate all changes
- Balance needed with DRY principle
Implementation Example
// Before: YAGNI violation
class UserManager {
constructor() {
this.users = [];
this.cache = new Map(); // Not needed yet
this.auditLog = []; // Not needed yet
this.featureFlags = {}; // Not needed yet
}
addUser(user) {
this.users.push(user);
}
getUser(id) {
return this.users.find(u => u.id === id);
}
// Future features not needed yet
enableCache() {
// Implementation not needed
}
logAudit(action) {
// Implementation not needed
}
}
// After: YAGNI applied
class UserManager {
constructor() {
this.users = [];
}
addUser(user) {
this.users.push(user);
}
getUser(id) {
return this.users.find(u => u.id === id);
}
}
// Add features when actually needed