Java DRY Principles#
What Is The DRY Principle?#
DRY
stands forDon’t Repeat Yourself
. It’s a software development principle with the goal of removing logic duplication.- The
DRY
code principle was originally made with software engineering in mind and coined byAndy Hunt
andDave Thomas
in their book,The Pragmatic Programmer.
They believed thatevery piece of knowledge must have a single, unambiguous, authoritative representation within a system
. As the field of analytics engineering and data transformation develops, there’s a growing need to adopt software engineering best practices, including writing DRY code.
Benefit#
- The advantages of the
DRY
principle include the following:- It makes the codebase easier to maintain since if we wanted to change the logic or add to it, we’d only need to change it in one place instead of multiple locations where the logic appears
- It makes the code easier to read because there’ll be less redundancy in the code
- It’s important to mention that misusing
DRY
(creating functions where we don’t need to, making unnecessary abstractions, and so on) can lead to more complexity in our code rather than simplicity.
Don't Be WET#
WET
, which stands forWrite Everything Twice,
is the opposite ofDRY
. It's a tongue-in-cheek reference to code that doesn’t exactly meet theDRY
standard. In a practical sense,WET
code typically involves the repeated writing of the same code throughout a project, whereasDRY
code would represent the repeated reference of that code.
See Also#
- Java Principles
- Java KISS Principle
- Java SOLID Principles
- Java Composition Over Inheritance Principle