0

It occurs to me that state control in languages like C# is not well supported.

By this, I mean, it is left upto the programmer to manage the state of in-memory objects. A common use-case is that instance variables in the domain-model are copies of information residing in persistent storage (i.e. the database). Clearly this violates the single point of authority principle, and "synchronisation" has to be managed by the developer.

I envisage a system where instead of instance variables, we have simple public access/mutator methods marked with attributes that link them to the database, and where reads and writes are mediated by a framework that decides whether to hit the database. Does such a system exist?

Am I completely missing the point, or is there some truth to this idea?

4

2 回答 2

1

如果我正确理解您想要什么:任何具有延迟加载的 OR-Mapper 都以这种方式工作。例如,我使用基因组,每个实体都是一个纯代理,你有很大的影响力告诉 OR-Mapper 如何缓存字段。

于 2010-12-23T18:21:39.250 回答
0

实际上存在数据普遍性的概念(由prevayler在 Java 中实现),其中内存中的对象是数据的单点授权点 (SPA)。

此外,一些对象数据库(如db4o)模糊了对象表示和“存储”表示之间的界限。

另一方面,通过将 SPA 引入应用程序内部,您需要自己处理事务和/或数据持久性。在诸如JVSTM 之类的事务性内存系统上已经做了一些工作(目前由我以前大学的信息系统使用),但它并没有被广泛使用。

另一方面,如果数据存在于数据库中,您可以在一切正常时提交数据(或使用数据库中内置的事务支持)并确保数据没有损坏或丢失。您以 SPA 原则换取更好的数据可靠性和事务(以及使用单独数据存储的其他优势)

于 2011-04-06T09:52:44.643 回答