Note that there are some explanatory texts on larger screens.

plurals
  1. POArchitecture for status managment
    primarykey
    data
    text
    <p><em><strong>What I have:</em></strong></p> <p>One-to-many relationship between A and B entities. Each of those entities have a status. There are a finit amount of statuses, about 7-12 for each. </p> <p><strong>I have to check if the transition (from one status to another) is possible</strong>. And make few additional tasks on transition, like store history and make logging.</p> <p>Don't fall in delusion, status isn't equals to state. It isn't about <code>State Pattern</code> because my entities haven't any state-based logic. </p> <p><em><strong>How does it happen:</em></strong> </p> <p>Entity arrives as a part of update request, and I compare if old version of entity has the same status as the new version. If not - the status has been changed. Status is just a string or enum.</p> <p><em><strong>What I want:</em></strong></p> <p>Of course, there are some rules, which impose restrictions on state transition. I want the next: </p> <ol> <li><em>Transition verification</em>. Means I want to check if the entity CAN be moved to the asked state. <em>Example:</em> <code>A-entity</code> can be moved to <code>Y-state</code> only if it is in <code>X-state</code> and all related <code>B-entities</code> are in <code>Z-state</code>. </li> <li><em>Automatical transition (not in all cases)</em>. Means the state of <code>A-entity</code> should always be consistent related to all linked <code>B-entities</code>. <em>Example:</em> If I move <code>B-entity</code> to <code>X-state</code> than related <code>A-entity</code> should be moved to 'Y-state'.</li> <li><em>Store history</em>. Means which entity and when was moved to the state.</li> </ol> <p><em><strong>What a problem:</em></strong></p> <p>The simples solution is to write a transition-matrix, where <code>matrix[i][j] == 1</code> if transition is possible and <code>0</code> otherwise. But there are some problems:</p> <ol> <li>What about situation when the transition is depend not only on the state of updated entity? Matrix doesn't solve this problem.</li> <li>What about history and loging?</li> <li>How to avoid a lot of <code>if-statements</code>? </li> </ol> <p><em><strong>Question</em></strong></p> <p>I'm looking for Pattern/Common Practice suitable for this situation. <strong><em>What is a patter/best practice of solving the task?</em></strong></p>
    singulars
    1. This table or related slice is empty.
    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. 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