The formats for both countries are very similar, although several details are different:
- The value of the digit for the sex
- The length of the random part, and therefore the length of the entire number
- The number the checksum must be a multiple of
This problem can be solved using the template method design pattern, which defines the skeleton of an algorithm and lets subclasses redefine particular steps:
social_number_generator is a base class that has a public method called generate() that produces a new social security number for a specified sex and birth date. This method internally calls several protected ...