How to Store Object State/Data for Later Processing

designobject-oriented

What do you think would be the most effective solution to maintain an object status through a life cycle? The goal to be able to be continue from any state any time. During the life cycle likely to have human interactions over a variety of interface.

For example, an order which needs to be approved by a few people. Or a data supply process that can requires many people to approve or edit?

In my mind some solutions:

  • When called a function serializes the object and saves it in a database.
  • All steps of the process would be saved to somewhere (database, csv, xml, etc.), so it can always be recreated based on this.
  • Possibly a mixture of the two methods?

Any good methods for the problem?

Best Answer

It sounds for me that you are mixing two problems into one here. In order to implement an object that can “continue” from any state, you probably need to implement a state machine.

As for serializing the object in case you need fault tolerance or some kind of persistence, you can use a lot of things — a database like SQL, No-SQL, Berkeley DB, or maybe a simple binary file, shared memory, or something like that. Which one to use depends on what exactly you need or what you already have.

In terms of what design patterns you may use, check these out:

Related Topic