Object Oriented Design Principle: Don’t Repeat Yourself (DRY)


DRY principle, as the name it implies, you should not make duplicate code.   I think it’s the most fundamental principle among others. However, many of us violate this principle. 

Less code, less bugs

If you found duplicate a code, move that code to a reusable unit like methods. By that way, you’re making less codes and when the time comes that you need changes or fix a bug, you can easily refractor it because it’s already in a single sensible place. 

Imagine 10000 lines of code full of duplication, that’s really a maintenance nightmare.


If you need to change a code, you’ll also to change other duplicates. This principle is pretty simple but it’s the most important practices in software development.

I’m not gonna provide you a example for DRY. Instead, try to read your code on your projects and spot for duplicate code and refractor it. You’ll gonna benefit it in the long run.

But, DRY isn’t not all about code

But DRY principle is more than just about duplicate code. According to the book, The Pragmatic Programmer, DRY defines,

Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

DRY can be also applied to writing requirements, making use cases or anything involved in the system. Making sure that you implemented the requirement once and making sure use cases don’t overlap.

After all, DRY is not just removing or avoiding duplication, it’s also about making good decisions about how to break system’s functionality.

For more design principles, click here.

If you liked this post, please share this post or subscribed to my blog.


2 thoughts on “Object Oriented Design Principle: Don’t Repeat Yourself (DRY)

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s