mardi 22 septembre 2020

How to refactor hard coded statuses in code with less code rewriting?

I'm using some hard coded statuses in my app to track the status of an order. For an example

1 - draft
2 - placed
3 - completed

Currently I'm keeping them in a database table as order statuses. In the app level I'm using these status to validate the order updates. Such as

  • If order status = 1, it cannot be completed.
  • If order status = 2, it cannot be deleted.
  • If order status > 2, it cannot be edited.

What I'm not sure is in the future requirements there can be new statuses between current statuses. Like

1 - draft
2 - placed
3 - partially completed 
4 - completed

How to prevent code rewriting in these kind of situations, I would have to rewrite all the conditions in the future if there are several statuses in between the current statuses.

Aucun commentaire:

Enregistrer un commentaire