CodePark/ questions / DRY, KISS, YAGNI & coupling
START PRACTICINGPRACTICE
Backend question · Software design & patterns › DRY, KISS, YAGNI & coupling

Two validators both contain value.length >= 8: one for passwords (a security policy) and one for coupon codes (a marketing format). What should you do?

Keep them separate, because they are different rules that only happen to match today

Keep them separate. DRY (Don't Repeat Yourself) is about duplicated knowledge, not duplicated text. These two rules have different owners and will change for different reasons.

"Extract a shared
isValidLength(value) helper" or a shared ValidationConstants.MIN_LENGTH would tie a security policy to a marketing format. If marketing changes the coupon length, password security changes by accident. Merging them is the wrong abstraction, not good DRY.