Today, when I was walking around the csdn, I suddenly saw a question post:
Ask everyone a question.
A string plus 1 who did
such as ka001a001
Next is ka001a002.
To ka001z999
Just ka002a001.
This immediately aroused my interest. Serial numbers (serial number) are widely used in the program, and the generation rules are different. (for example, our company's membership card number rules inside there is a "card number encountered 4 Skip" option. I went to Google a simple search, found that are hard-coded functions, although they can solve the specific problem, but not versatile and flexible, change the application scenario and need to rewrite the code. Is there a simple, versatile and flexible serial number generator? Let's try it out today.
Flow numbers are generally fixed in length and are composed of several parts:
Dates (such as: 20090101)
Constant code (for example, KA)
Number sequence (eg: 0001-9999)
Alphabetical sequence (e.g. A-Z)
Special characters, such as:-)
After a simple analysis, we first define an interface (Delphi):
Iserialnumbergenerator
1ISerialNumberGenerator =interface
2 functionNextSerialNumber(const serialNumber: string): string;
3 functionValidate(const serialNumber: string): Boolean;
4end
The Iserialnumbergenerator interface has two main functions (responsibilities):
Generate the next available serial number (Nextserialnumber)
Verify that a serial number is legitimate (Validate)
OK, Next we'll make a simple list of tasks:
Task List
Supports a serializable sequence of numbers (' 001 '-' 999 ')
Supports recyclable alphabetic sequences (' A '-' Z ')
Support for constant code (' KA ')
Supports alphabetic sequence and number sequence combinations (ka001a001)