DRY
Every piece of Code
must have a Single, Unambiguous,
representation within a Software Entity
DRY Abstract:
Software’s primary technical imperative
is to managing complexity
Object Oriented Programming gives us the tools to accomplish this imperative through one of the three pillars: Encapsulation.
Data hiding or encapsulation states that the details of how a Software Entity accomplishes its objective should be hidden as much as possible from the consuming entity.
The Don’t Repeat Yourself (DRY) Principle dictates that the developer complies with code reuse through encapsulation of common dependency responsibilities.
If an Entity Type or Code Block has a “More Than One” relationship with any other Software Entity it should be refactored into an encapsulated, reusable entity.
Software Complexity can be Better managed
… By Ensuring that Code “Cut and Paste”
….. Is Always a Code Smell in Code Review
Description:
DRY is not always just about repeating code through “Cut and Paste”.
We should be determining if a code block is required in more than one place.
If the code block has a “One and Only One” relationship to a consuming Type it is nested inside the Type as a Private Helper Method.
If the code block will be consumes by a “More Than One” relationship to the assembly then Public Common Helper Methods located inside a Common Utilities Class should be created.
Cut and paste of common code is never a good practice
The creation of reusable Helper Methods, both as Private Methods inside a consuming class and Common Public Methods inside of assembly level Common Class, will create a library of common functionality for all developers.
The following two tabs change content below.
I am a Principal Architect at Liquid Hub in the Philadelphia area specializing in Agile Practices as a Certified Scrum Master (CSM). I use Test Driven Development (TDD) and Acceptance Test Driven Development (ATDD) with Behavior Driven Development (BDD) as my bridge to Agile User Stories Acceptance Criteria in a Domain Driven Design (DDD) implementing true RESTful services
Latest posts by Brad Huett (see all)
- DevOps: A Bridge to Your DevOps Culture - March 25, 2016
- Embracing Test Driven Development (TDD) - March 25, 2016
- DevOps: Delivering Agile Projects - March 25, 2016