Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The A- and B-items should probably implement the same interface, such as</p> <pre><code>boolean canMove(State newState); // A-items know which B-items to check void performMove(State newState, HistoryAndLog historyAndLog); // A-items and B-items will record history and log as appropriate. A-item will change related B-items as appropriate </code></pre> <p>In this case we are using composite (A-items check if related B-items can change state as desired) and delegation (have A- and B-items update the log and store history as they see fit). This removes the need for a lot of the if-statements.</p> <p>The underlying design of the A- and B-items should probably be "state pattern", perhaps combined with Flyweight so you can use an underlying transition matrix to implement part of the logic. </p> <p>EDIT: Expanding on Flyweight... For an N x M transition matrix, storing just a yes/no value takes one bit. If instead you have to store an object pr. cell, that would cost a LOT more (internal representaiton of object). Instead it's cheaper to create a temporary object on request from a factory class. Often by a factor of 100 or more pr. object.</p> <p>Basically you are trading computation in the situation (create the object on demand) for storage (avoid storing N x M objects).</p> <p>One could imagine something like this</p> <pre><code>class Factory { private boolean canTransitionItemA(final int n, final int m) { // Look up in matrix } public ItemType makeItemAFromCoordinates(final int n, final int m) { return new ItemA() { public boolean canTransition(&lt;blabla&gt;) { return canTransitionItemA(n, m) &amp;&amp; canTransitionRelatedBItems(n, m); } &lt;bla bla bla&gt; } } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload