liveBook · Manning

Don't repeat yourself principle

As explained in Microservices Patterns, Second Edition

A design principle requiring each piece of knowledge in a system to have a single, unambiguous, authoritative representation.

DRY requires each piece of knowledge to have one unambiguous, authoritative representation. For an algorithm, that means implementing it once rather than copying it across the system. This can reduce design-time coupling: a rule change then has one location to update. section 4.2.4

FTGO order totals

The order total calculation was copied in multiple places while it remained stable. When FTGO added a COVID surcharge, changing the rule meant updating each implementation; a single implementation would need changing only once and avoid inconsistent versions. section 4.2.4

Figure 4.5 Applying the DRY principle replaces multiple implementations of a business rule with a single implementation. As a result, a change only needs to be made in one place, and there’s no risk of bugs caused by inconsistent implementations.
an example of dry

Shows multiple business-rule implementations replaced by one, localizing changes and reducing the risk of inconsistent implementations. section 4.2.4

How Microservices Patterns, Second Edition covers it

How deep it goes
Defines a single authoritative representation and illustrates its impact through duplicated business logic.
Examples
Uses FTGO order totals and a COVID surcharge to show the cost of duplicated calculations.
What you can do after
Apply it by consolidating an algorithm so a rule change is made in one place.
How it connects
Connects DRY with loose design-time coupling and API stability.

Also explained in

Compare how 11 books explain don't repeat yourself principle →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Microservices Patterns, Second Edition. The section links point to the parts of the book it draws on.