I have a method ‘ABC’ that does some stuff. The ABC method is called from another method, method XYZ. Where should the data validation of the input values occur?
Should I validate in XYZ before even calling ABC? If it’s bad data method ABC won’t even be called.
Or, should I validate in ABC?
Or, validate in both locations?
It depends.
If ABC is only ever called by XYZ then you can validate by XYZ.
If ABC has visibility outside of XYZ (for example it’s a public method, or an internal one) then you should validate in ABC.
If it’s a critical function (ABC = AtomicBombControl) then validate everywhere you can.