views:

128

answers:

1

I'm working my way through Fowler's Analysis Patterns and programming examples for myself in Clojure as way of developing a better understanding of both.

Putting persistence/durability issues to the side for the moment[1], it seems that Clojure refs with their synchronization would be the obviously best approach.

On the other hand, given Posting Rules that are triggered by entries into the account, producing more transactions in yet more accounts, perhaps agents, and their asynchronous updates would be better. At this point it looks like I might have to try a bit of both. Anybody have any suggestions on this particular design decision?

[1] I'm assuming if I can get the functionality and concepts working nicely, I'll be able to map everything into a sensible DB schema later.

+2  A: 

All of the mutable objects in Clojure are designed to give you a consistent view of how things change over time. If you have multiple objects changing in relation to each other then you need to create a timeline that includes all of them and refs are designed for just that purpose.

you may also be interested in the concept of watchers (add-watch reference key fn) that you can add to refs to enforce transaction invariants.

Arthur Ulfeldt
+1 Thanks, I was unfamiliar with watchers. They might be the missing piece I was looking for.
CBFraser