instiki/vendor/madeleine-0.7.1/docs/designRules.html

88 lines
2.7 KiB
HTML
Raw Normal View History

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN">
<html>
<head>
<title>Design rules - Madeleine</title>
<link type="text/css" href="docs.css" rel="stylesheet">
</head>
<body>
<h1>Design rules</h1>
<p>This is a summary of the design rules your application has to
follow to work with Madeleine.
<h2>The Prevalent System</h2>
<h3>Your objects have to fit into memory</h3>
<p>All of them. At the same time.
<h3>Your objects have to be marshallable</h3>
<p>Snapshots are taken of the system by marshalling the whole system to a
file. If your classes can't be marshalled/unmarshalled then Madeleine
won't be able to store/restore the system.
<h3>Your objects have to be deterministic</h3>
<p><em>Deterministic</em> means that, given the same commands, they have
to always give the same results.
<p>For the much of your code this won't
be a problem, but there are a few common issues:
<h4>The system clock</h4>
<p>You can't use the system clock (see instead ClockedSystem and TimeActor).
<h4>Random numbers</h4>
<p><code>Kernel.rand()</code> uses the system clock internally by
default. Use <code>Kernel.srand()</code> to seed the random number
generator before using <code>rand()</code>.
<h4>Files, network and other IO</h4>
<p>You generally can't access the outside world from within your
prevalent system. Instead do IO outside of the prevalent system and
call into the system when needed.
<h3>Changes to the system have to be done through command
objects</h3>
<p>Everything that modifies the prevalent system must be done through a
<em>command object</em> sent to the Madeleine instance, using
<code>execute_command(aCommand)</code>. Queries that don't modify the
system can be done either through direct method calls or through
command objects.
<h2>Command Objects</h2>
<p>A command object is an object that implements the method
<code>execute(system)</code>. They are an example of the "Command"
design pattern.
<h3>The command objects also have to be marshallable</h3>
<p>Madeleine keeps track of changes between snapshots by logging
marshalled commands.
<h3>The command must raise errors before modifying the system</h3>
<p>Unlike a RDBMS, Madeleine can't roll back a command (yet). This means
that your commands will have to do their error checking and raise any
errors before modifying the system. Failing to do this will cause an
inconsistent command log.
<h3>Command objects can't hold references to the system's objects</h3>
<p>Unmarshalling such a command would create clones of the original
objects, which would then be modified instead of the real
objects. The commands must <i>find</i> the objects to modify.
<hr>
<tt>$Id: designRules.html,v 1.1 2005/01/07 23:03:27 alexeyv Exp $</tt>
</body>
</html>