Field-driven design practice--Serial number generator (upper)

Source: Internet
Author: User
Tags constant generator

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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.