Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Basically, you want to rip out that big if/switch statement in GetProductionTime and turn each case into various smaller, sensible classes. Each class will be a different strategy that calls CalculationFast or CalculationSlow using different conditions.</p> <p>For instance, if your language supports inner classes (Java) and Plantype only needs to inspect the state of Product to decide between fast &amp; slow:</p> <pre><code>public interface Plantype { public int Calc(); } public class Product { public class Plantype_one implements Plantype { public int Calc() { if (&lt;some simple condition holds for Product instance&gt;) { return CalculationFast(); } else { return CalculationSlow(); } } } public class Plantype_two implements Plantype { public int Calc() { if (&lt; some different &amp; simple condition holds for Product instance &gt;) { return CalculationFast(); } else { return CalculationSlow(); } } } // etc. public int GetProductionTime(Plantype plantype) { return plantype.Calc(); } private int CalculationFast() { //do fast calculation depending on many fields of product return result; } private int CalculationSlow() { //do slow but more accurate calculations depending on many fields of product return result; } } </code></pre> <p>Basically, your algorithm can pick and choose what sort of Plantype makes sense at a given point and pass it along into GetProductionTime.</p> <p>The inner class approach may be totally wrong, depending WHAT the Plantype class needs to inspect but you get the picture.</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