What design pattern do you suggest for the following case:
A class is needed to represent the serial string of some documents which consists of numeric characters. There are 4 types of serials and the first character of the string specifies the type of serial. Each type of the serial has some numeric fields that are separated by the pipe character. Serial types differ only in the number of fields that they have (which is fixed for each type). The meaning of each field is irrelevant and can have arbitrary values. A serial string ends with a pipe character that is followed by a two-digit checksum of all preceding numeric values of the serial. For example, the following string represents a type 2 serial number:
20202|5666|00020|31
Here, the first digit, 2, specifies that the serial is a type-2 serial. The serial string has 3 fields and the checksum of the serial is the last two digits, 31, which is simply the sum of all preceding numbers.
In this case, it is fairly easy to solve the problem without using any particular pattern but I'd like to know what famous patterns can be utilized to solve this problem or similar ones (for example, parsing MICR data of banknotes).
Aucun commentaire:
Enregistrer un commentaire