-
Notifications
You must be signed in to change notification settings - Fork 0
Duplication
Vanskarner edited this page Jul 26, 2023
·
7 revisions
The duplication of certain software elements does not necessarily imply a violation of the DRY (Don't Repeat Yourself) principle mentioned in the book The Pragmatic Programmer: From Journeyman to Master (1999) by Andrew Hunt and Dave Thomas. There are 2 types of duplication:
False Duplication | True duplication | |
---|---|---|
Description | Seemingly duplicated sections of code evolve divergently, undergoing change for different reasons and at different speeds. This duplication is perfectly valid and should not be eliminated. | Each alteration in an instance implies the same alteration in each duplicate of that instance. This duplication must be removed. |
Example | One data structure in the persistence layer and another in the presentation layer are similar, but will change independently in the future. | The calculation of the price of a product is performed in different parts of the code. This duplication means that any changes to the calculation must be made in several places. |
Before deleting duplicate items, it is important to make sure that it is a true duplication. If a false duplication is removed, it will make it difficult to separate later.