Clojure 中的财务账户模式实现:ref 还是代理?

发布于 2024-08-13 01:56:03 字数 538 浏览 4 评论 0原文

我正在研究 Fowler 的 分析模式 以及我自己在 Clojure 中的编程示例作为更好地理解两者的一种方式。

暂时将持久性/持久性问题放在一边1,Clojure 似乎refs 及其同步显然是最好的方法。

另一方面,考虑到通过帐户输入触发的过帐规则,在更多帐户(也许是代理)中产生更多交易,并且它们的异步更新会更好。现在看来我可能必须两者都尝试一下。 有人对这个特定的设计决策有什么建议吗?

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 moment1, 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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

半窗疏影 2024-08-20 01:56:03

Clojure 中的所有可变对象旨在为您提供事物如何随时间变化的一致视图。如果您有多个彼此相关的对象发生变化,那么您需要创建一个包含所有这些对象的时间线,而 refs 就是为此目的而设计的。

您可能还对观察者(add-watch引用键fn)的概念感兴趣,您可以将其添加到引用中以强制执行事务不变量。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文