-Excerpt from Icculus by PhishThere are few mantras that are as universally agreed upon by Software Engineers as Don't Repeat Yourself or DRY. It rings deeply and globally true that any form of code duplication is at best a compromise, at worst, an abominable trap. Writing and maintaining code is difficult enough without doing it many times. So if we all know this, and we all agree, then why is it that the industry's preferred architectural best practices embrace duplication?
If you've ever built a controller, a repository, a service layer, a data access provider, or anything remotely like one of these things, you know exactly what I'm talking about. Duplication is what you do. You copy the logging code. You copy the query strategy. You copy the update methodology. You copy the attributes and data structures. You copy the exception handling pattern. "That's how it was shown to you by smart people, so it must somehow be right," you think as you faithfully type away, all the while wondering if you've become little more than a digital version of a truck driver.
Like the proverbial cliff all your friends jumped off of according to your mother, it doesn't matter how bad of architecture you have seen, there is another, better way... so stop it! But perhaps you're so used to following your lemming-like friends that you don't know how to escape the allure of duplication? I'll offer some suggestions.