Three useful software principles are YAGNI, KISS, and DRY.
Build only what you need right now. Don’t add features just because you might need them later.
public class User {
private String name;
private int age;
public User(String name, int age) {
this.name = name;
this.age = age;
}
}Avoid adding unnecessary fields “just in case.”
Write code that is easy to read and understand. Simple code is easier to maintain and debug.
public static List<Integer> getEvenNumbers(List<Integer> numbers) {
return numbers.stream()
.filter(number -> number % 2 == 0)
.toList();
}Don’t make code more complicated than necessary.
Avoid writing the same logic in multiple places. Put repeated logic in one reusable method.
public static String getProductName(Product product) {
return product.getName();
}
public static double getProductPrice(Product product) {
return product.getPrice();
}A better approach is to access product properties through the object’s existing methods instead of creating unnecessary duplicate logic.
public class Product {
private String name;
private double price;
public String getName() {
return name;
}
public double getPrice() {
return price;
}
}- YAGNI: Build only what you need.
- KISS: Keep your code simple.
- DRY: Avoid repeating code.
Following these principles helps you write cleaner and more maintainable software.