DEV Community


Discussion on: Don't let duplication mislead you

lambdude profile image
Ian Johnson

Great topic. I've seen this as a source of frustration from many devs trying to push a round peg into a square hole. It really underscores the need to think, rather than just blindly following mantras and anecdotes. I read a similar article not long ago.

From DRY revisited:

Can it be that two classes have identical parts yet still don’t break DRY? Yes. The DRY principle restricts the presence of domain knowledge, it doesn’t put any bounds on the actual code which is required to express that knowledge. The fact the two entities have the same functionality doesn’t mean they violate DRY. In fact, both the Product and the Customer classes hold their own semantics. It just happened that they do it using the identical code in this particular case.