What is a good way to keep changes to a resource in sync with both in-memory and persistent storage in a multi-user situation? Here's two ideas, but they're both clumsy
Candidate A
Here, a copy of r
must be retrieved so that in-memory state and persistent state is updated at the same time on put
.
Resource r = resources.getDeepCopyOfResourceById("foo");
r.removeValue("bar");
resources.put(r);
Candidate B
Here, update operations are located on the service level. This appear to me as an object-oriented anti-pattern.
Resource r = resources.getResourceById("foo");
resources.removeValue("foo", r);
Is there a better way to design this?
Aucun commentaire:
Enregistrer un commentaire