Identifier for the “completed” stage of a process: 0, 99, something else? [closed]

Say, that you are handling a multi-step process (like a complex registration form, with a number of steps the user has go through in order). You need to be able to save the current state of the process (e.g. so the user can come back to that registration form later and continue form the step where they were left off).

Obviously, you’ll probably want to give each “step” an identifier you can refer to: 1, 2, 3, 4, etc. Your logic will check for this step_id (or whatever you call it) to render the appropriate data.

The question: how would you identify the stage after the final step, like the completed registration state (say, that you have to give that last “step” its own id, that’s how your logic is structured). Would it be a 0, 999, a non-integer value, something else entirely?

I wouldn’t store a step_id at all, as you’re just limiting yourself in the future. Break it down into 2 groups of orders:

  • Incomplete order
  • Complete order

Just use a boolean to store that. So you only have to worry about incomplete orders now (which are proportionately few compared to the total number of orders in your system). Now every required detail that they have to enter has to be it’s own field:

  • Name
  • Street
  • City
  • etc.

Now in the future you may want to divide your steps up in various ways. There’s a tendency now to move away from steps and towards a single long page where the user can jump around and enter it in whatever order they want, but there might be steps.

So when you reconstitute an incomplete order, you have something like:

OrderStep currentStep(Order incompleteOrder)
{
    if(!step1FieldsComplete(incompleteOrder))
    {
        return OrderStep.One; // silly naming, I know, but give it more meaningful name
    }
}

bool step1FieldsComplete(Order incompleteOrder)
{
    return 
        incompleteOrder.Name != null
        && incompleteOrder.Street != null
        && ...;
}

Now, when you want to move fields from one step to another, or merge 2 steps into one, you have lots of flexibility, and the code will even work if you add new fields in a previous step that the customer already filled out. When they come back they’ll just be bumped back to the step with the new field.

I would consider something like a state table (or stage table (or step table)). This table would consist of an ID and a Description, and potentially anything else you feel needs to be associated with a state/stage/step. Just try to find some sort of relevant descriptor about each step – this hopefully wouldn’t be too difficult.

1 – Start
2 – Personal Info
3 – Address Info
4 – Another state
5 – Completed

Ideally, additional steps would not be added down the road, but captured up front in the design process. Just a thought.

People like to count in order, so systems like this often involve sorting the pages by ID number. Page IDs tend to go in steps of 10, though any arbitrary number can be chosen. This allows you to later insert pages between existing pages without renumbering any existing pages.

Using an unusually high value such as 999 for the final page allows you to insert any reasonable number of pages without having to renumber your final page. This is perfectly reasonable.

 10 Start page
 20 Welcome
 30 Select products to install
 35 Configure products          <-- Page inserted later
 40 Select folder to install to
 50 Confirm installation
 60 Display install progress
999 Finished

I wouldn’t really make a table with numeric identifiers but more something like this:

Current | Next
--------------
Start   | Page1
Page1   | Page2
Page2   | End
End     |

This way you can easily fit a page in between. And your end page would be the one with an empty(nil) Value.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật