Refactoring with Weighted Sum Check digits
In the previous post, I added UPC-A checkdigit verification to my ISBN verification code. This was a departure from the “theme” of the previous work which was focused on ISBN-10 and ISBN-13 codes alone. As I did this work, I made a few observations:
- Most of the check digit calculations were VERY similar, but not quite identical
- The group of methods/functions no longer were solely ISBN specific
- Duplicate code was starting to pop up in the class
Based on this, I decided to do a quick refactoring exercise and see if I could simplify things a bit.
…