Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Daniel, it seems that the code listing you shared and the code listing on the Ruby Gem Workflow (<a href="https://github.com/geekq/workflow" rel="nofollow">https://github.com/geekq/workflow</a>) - define states, events, transitions and actions on the model objects.</p> <p>Code Listing from the <a href="https://github.com/geekq/workflow" rel="nofollow">Gem Workflow link</a></p> <pre><code>class Article include Workflow workflow do state :new do event :submit, :transitions_to =&gt; :awaiting_review end state :awaiting_review do event :review, :transitions_to =&gt; :being_reviewed end state :being_reviewed do event :accept, :transitions_to =&gt; :accepted event :reject, :transitions_to =&gt; :rejected end state :accepted state :rejected end end </code></pre> <p>For MVC and SOLID, I think if this code can be modified in such a way that Workflow applies to Controller instead of the Model.</p> <p>Model is an instance object of domain entities - Message or Article. They don't define workflow themselves. They can be in any state any time. It is the system requirements that has a context of states for any given model objects. For example a message itself doesn't care if its spam. An Article itself does not have a tag that its new, rejected, approved, submitted or being reviewed.</p> <p>Hence if Controller is given the Workflow responsibilities, then controller will handle events, will take actions and will do state transitions. In that, the actions taken by the controller may perform necessary work to modify model objects.</p> <p>Real like analogy: Author starts writing article in his notebook (with pen). Keeps it with him till its not satisfactory. The article itself has know meaning that its new / fresh. Then author submits the article for review. The article moves to the reviewer desk, yet Article itself can't define the state that it can't be modified. and so on.</p> <p>Does that make sense!?</p>
 

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