DRY

Don’t Repeat Yourself. Make sure to only repeat yourself if it is maintainable for future changes.

"Don’t Repeat Yourself" means avoid duplicating logic across your codebase. If the same piece of code appears in multiple places, a future change will require updating all copies, which is error-prone and time-consuming.

Bad example:

public BigDecimal addVat(BigDecimal price) {
    return price.multiply(BigDecimal.valueOf(1.19));
}

public BigDecimal calculateTotal(BigDecimal price, int quantity) {
    return price.multiply(BigDecimal.valueOf(quantity))
                .multiply(BigDecimal.valueOf(1.19));
}

Here the VAT logic is duplicated. If the VAT rate changes, you must hunt down all occurrences.

Better example:

public class VatCalculator {
    private static final BigDecimal VAT_RATE = BigDecimal.valueOf(1.19);

    public static BigDecimal addVat(BigDecimal base) {
        return base.multiply(VAT_RATE);
    }
}

Now the VAT calculation lives in one place. Any future changes require editing only this class.

That said, DRY is not about blindly removing all repetition. Sometimes small duplication is more maintainable than forcing an abstract solution that nobody understands. The rule of thumb: duplication is fine if removing it would make the code harder to read or maintain.

Before committing, ask yourself: Am I repeating logic that might need to change in the future? If so, can I extract it safely without overengineering? Practicing DRY keeps your code cleaner, easier to maintain, and less fragile.