Example
1public class User {
2 private String name;
3 private int age;
4
5 // YAGNI violation: A method to calculate the user's retirement age,
6 // which is not currently necessary for the User class.
7 public int calculateRetirementAge() {
8 return 65 - this.age;
9 }
10}Description
Keep things simple and avoid investing time and effort in building features based on assumptions about what the future might hold.
YAGNI is like a friendly warning against filling your backpack with too many "just in case" items for a hike; it only weighs you down.
This approach aligns with Agile methodologies, which emphasize iterative development, responding to changes, and streamlining work to what's currently valuable.
