Add code instead of changing it

As a project grows, we have to add the new functionality.

Let’s say we need to add a new validation rule for the old field. We’ve got 2 options:

  1. find the existing validation for this rule and change it, which will affect al the existing usaes and tests
  2. add one more rule, covered by tests and use it only wherever it’s needed

The second way is considered to be preferable because of:

  1. adding the code does not affect existing use cases
  2. can be removed easily
  3. less coupled to existing code
  4. can be easily covered by tests, because of you don’t have to re-create the state of all the existing code, in order to test your piece