dimanche 17 janvier 2016

Is there any pattern dor changing state of the object on schedule?

The situation is following:

  • I need to keep a lot of objects (let's say Food) in database (in my case it's MySQL).
  • Each object has a property State which is enumerable taking one of "FRESH", "STALE" or "SPOILED".
  • Each object changes its state according some schedule. For instance, an object Bottle of milk is created with FRESH state, but after 2 days it becomes STALE, then after next 3 days it becomes SPOILED.

The question is: is there any pattern that allows me to control states of objects and change them accordingly? For instance, I can run some script every 30 minutes, select all the objects, inspect their states and change them. But this approach looks suboptimal, I'm trying to find out something better.

Aucun commentaire:

Enregistrer un commentaire