Search code examples
javastatusmodeling

modelling status of an Order


What is the best way to model the status of an Order?Currently I am doing it the dirty way,by hardcoding like below

class Order{
   ...
   String orderStatus;
   ...

   public Order(){
     ...
     orderStatus = "pending";
   }
}

Later on when the status is changed to say confirmed,I would

myorder.setOrderStatus("confirmed");

But,I begin to smell it is not the right way..What should be the correct way of modelling it?Should I use Enumerations?..


Solution

  • Using an Enum would be a lot better than using random strings yes.

    I would look into the State design pattern, otherwise I think you might well end up with lots of code that is conditional on the current state variable which is also pretty smelly.