Question

I have been reading about the DRY principle. Though it seems so easy, I am having difficulty in understanding how we actually achieve it in any project, be it a web application or Swing.

Maybe a few examples will give me a lead and help me in developing my thought process.

I have tried to search on Google, but I could not find anything suitable.

Was it helpful?

Solution

DRY is nothing that requires examples. If you are copying and pasting blocks of code from one method, function or block of code to another, then you are in violation of DRY.

Very simply, DRY tells you to move that code into a reusable unit: either into a function or method or macro, or other mechanism relevant to your programming language. If you have places in your codebase where you clearly have very similar code (even with minor variations) then you should be looking to refactor that code to make it DRY.

"Don't repeat yourself!" == "Don't write the same code repeatedly"

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top