♻️ Software Design Principles · Core Principles
DRY - Don't Repeat Yourself
Avoid unnecessary duplication of knowledge or business rules.
If the same rule exists in many places, a future change can easily become inconsistent.
Put age eligibility validation in one shared rule instead of copying it into five forms.
💡 Like one master recipe card everyone cooks from — not five handwritten copies that slowly drift apart.
💡 Why it matters
When the same rule is copied into many places, a change must be made everywhere at once, and one missed copy creates a bug. Keeping each rule in one place means you change it once and the whole system stays consistent. This is really about one source of truth, not just avoiding similar-looking code.
🛠️ How to achieve it
⚠️ Signs of trouble
- •The same rule is copy-pasted across several files.
- •A bug fix has to be applied in many places.
- •Two copies of a rule have quietly drifted out of sync.
- •The same magic number appears all over the code.
🎯 Quick check
Score: 0/3Three questions to test the idea.
1. What is DRY really about?
Answer: Keeping each piece of knowledge in one place
DRY means one source of truth for each rule, so a change is made once and stays consistent.
2. When should you NOT merge two similar-looking blocks of code?
Answer: When they only look alike but may change for different reasons
Code that is similar by coincidence can diverge later, so forcing it together causes more harm than good.
3. The minimum age 18 appears in five files. What is the DRY fix?
Answer: Define it once as a named constant everyone uses
A single named constant means changing the age once updates every place at once.
