# You Aren't Gonna Need It (YAGNI)

> Don't implement functionality until you actually need it.

- **Category**: Dry Yagni
- **Subcategory**: principles
- **Canonical URL**: https://designpattern.fyi/patterns/yagni/

---

## 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.'



## Use Cases
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.



## Implementation Example

```javascript
// 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
```



## Trade-offs


### Advantages

- Simpler, focused code

- Faster development cycles

- Reduced maintenance burden

- Avoids waste on unused features




### Considerations & Drawbacks

- May require refactoring later

- Can't anticipate all changes

- Balance needed with DRY principle







