Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The first example is the most common pattern. The second to me is just a variation of the first with a less semantic naming convention. </p> <p>The third example I would stay away from. Exceptions shouldn't be used to direct the normal control of flow. <a href="http://msdn.microsoft.com/en-us/library/vstudio/ms229030(v=vs.100).aspx" rel="nofollow">http://msdn.microsoft.com/en-us/library/vstudio/ms229030(v=vs.100).aspx</a></p> <p>EDIT: I take that back. The second example looked similar but instead it asks the controller to determine whether the task can run or not. If the "runability" is based solely on the content of the task object and not based on some state of the controller then I see no need to complicate things by putting the check in the controller. If the logic is similar enough I would use a base task class to keep things DRY.</p> <p>EDIT: I'm not clear on your exact use case but so this could be off base completely but to me seems like the controller would ask the task if it is ready to run and if so it would run the task and if not it would do something else.</p> <pre><code>if (task.CanRun) { controller.Run(task); } else { //Do whatver. } </code></pre> <p>Furthermore, if the logic is encapsulated within the controller regarding what should be done when a task cannot be run then perhaps the run method should return a boolean so the caller can do something additional if need be. In that scenario the caller just passes the task to the controller run method and inside there the controller check if the task can run or not and acts accordingly.</p>
    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. This table or related slice is empty.
    1. 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