DRY (Don't Repeat Yourself) is commonly misunderstood as being about eliminating duplicate code, but it's actually about avoiding duplication of knowledge. Using PHP examples with Basket and Shipment classes, the post demonstrates that two pieces of identical code may represent distinct business rules that should change independently. Merging them into a shared abstraction introduces dangerous coupling — a change to one rule accidentally affects the other. The key insight is to look at reasons for change: if two pieces of code represent the same knowledge, they should be unified; if they represent different knowledge, duplication is intentional and correct.

4m read timeFrom verraes.net
Post cover image
Table of contents
Reasons to ChangeKnowledgeRead more