Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to fix an inconsistency of this factory model?
    text
    copied!<p>Maybe the title has no make sense. I'm creating factories, one of them is abstract. Abstract contains a Random variable, and <code>CanConfigureXLevel</code>. These one for default is false (I mean, is not available), but if you want to have it, just override it a change to true.</p> <pre><code>public abstract class ProblemFactory { protected Random Random = new Random(); public abstract IProblem Generate(); public virtual bool CanConfigureEasyLevel() { return false; } public virtual bool CanConfigureMediumLevel() { return false; } public virtual bool CanConfigureHardLevel() { return false; } protected abstract void ConfigureEasyLevel(); protected abstract void ConfigureMediumLevel(); protected abstract void ConfigureHardLevel(); } </code></pre> <p>A concrete class for Binary Problems (generate additions)</p> <pre><code>public class BinaryProblemFactory : ProblemFactory { private Bound&lt;int&gt; _bound1; private Bound&lt;int&gt; _bound2; public BinaryProblemFactory(Level level) { // ... } public override IProblem Generate() { int x = random.Next(_bound1.Min, _bound1.Max); int y = random.Next(_bound2.Min, _bound2.Max); Operators op = Operators.Addition; return new BinaryProblem(x, y, operator, answer); } public override bool CanConfigureMediumLevel() { return true; } public override bool CanConfigureHardLevel() { return true; } protected override void ConfigureEasyLevel() { // ... } protected override void ConfigureMediumLevel() { this._bound1 = new Bound&lt;int&gt;(10, 100); this._bound2 = new Bound&lt;int&gt;(10, 100); } protected override void ConfigureHardLevel() { this._bound1 = new Bound&lt;int&gt;(100, 1000); this._bound2 = new Bound&lt;int&gt;(100, 1000); } } </code></pre> <p>Bound is just a class which contains Min and Max generic value.</p> <p>Remember that BinaryProblemFactory contains a Random property. I'm creating several problems of mathematics, above is for addition problems, also I will create for times tables (very similar to BinaryProblem, but this is for multiplication and different bounds.</p> <p>I mean, each concrete factory needs a container of utils or objects to setup the program. Binary and TimesTablesFactory need two bound properties.</p> <p>My main problem is.. I need to show in a list which levels are available (above only two, medium and hard). I guess I can fix it overriding <code>CanConfigureXLevel</code> if we maintain a dictionary, where the key will be a Level enum and the value will be the conditions (bound objects).</p> <p>But I'm not sure what should I remove. I need a little of help.</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