Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7696555
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T21:48:25+00:00 2026-05-31T21:48:25+00:00

for sure this is not the best title. I’m creating a system to generate

  • 0

for sure this is not the best title. I’m creating a system to generate math problems. The developer must implement two interfaces:

  • Problem: This contains the properties which needs the problem generated.
  • Configuration: This is the range parameters to generate a Problem.

These are the interfaces:

public abstract class Problem
{
}

public abstract class Configuration
{
}

enter image description here

And here is one example for the BinaryProblem.

public class BinaryProblem : Problem
{
    public decimal X { get; set; }
    public decimal Y { get; set; }

    public BinaryProblem(decimal x, decimal y)
    {
        this.X = x;  // Number 1
        this.Y = y;  // Number 2
    }
}

public class BinaryProblemConfiguration : Configuration
{
    // Range for X
    public int XMin { get; set; }
    public int XMax { get; set; }

    // Range for Y
    public int YMin { get; set; }
    public int YMax { get; set; }

    public BinaryProblemConfiguration() { }
}

Can you see that line between Problem and Configuration? I need to put many Modules which implements those two interfaces.

So, I need a way to generate them. I was thinking in create an abstract class where contains:

  • protected static Random: Almost all configurations needs a random class to create the numbers (I.E. random.Next(X1, Y1);). And it’s necessary to be static because a need to create the numbers using the same seed always.
  • public abstract TProblem Generate(TConfiguration config); // where : TProblem : Problem, new(), TConfiguration : Configuration

And implement this abstract class in each problem type.

My question is: Is this a good way to start to solve this solution or what other solution do I have to do?

EDIT: One example which I was trying to is:

This is my abstract class, I mean my idea is when you instanciate this class, you specify the generic values:

public interface IProblemFactory
{
    Problem CreateProblem();
}

public abstract class ProblemBaseFactory<TProblem, TConfiguration> : IProblemFactory
    where TProblem : Problem
    where TConfiguration : Configuration
{
    private const int SEED = 100;
    protected TConfiguration _config;
    protected static Random _random;

    public ProblemBaseFactory(TConfiguration config)
    {
        _config = config;

        if (_random == null) _random = new Random(SEED);
    }

    public void SetSeed(int newSeed)
    {
        _random = new Random(newSeed);
    }

    public Problem CreateProblem()
    {
        return CreateProblem(_config);
    }

    public abstract TProblem CreateProblem(TConfiguration config);
}

public class BinaryProblemFactory : ProblemBaseFactory<BinaryProblem, BinaryProblemConfiguration>
{
    public override BinaryProblem CreateProblem(BinaryProblemConfiguration config)
    {
        var x = GenerateValueInRange(_config.Range1);
        var y = GenerateValueInRange(_config.Range2);
        return new BinaryProblem(x, y, Operators.Addition); 
    }

    private decimal GenerateValueInRange(Range<int> range)
    {
        return _random.Next(range.MinValue, range.MaxValue);
    } 
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T21:48:27+00:00Added an answer on May 31, 2026 at 9:48 pm

    I think it’s good to aggregate values that used together. In your case object Range will be useful. Something like (without verification min <= max):

    public class Range<T>
    {
        public Range(T min, T max)        
        {
            Min = min;
            Max = max;
        }
    
        public T Min { get; private set; }
        public T Max { get; private set; }
    }
    

    After that BinaryProblemConfiguration will look like this:

    public class BinaryProblemConfiguration
    {
        public Range<int> XRange { get; set; }
        public Range<int> YRange { get; set; }
    }
    

    What you actually implementing is products factory. So I Intermediary is not very descriptive name for it:

    public interface IProblemFactory
    {
        Problem CreateProblem();
    }
    

    Create factory for each type of products. Each factory knows what type of product it creates and what type of configuration it needs. E.g:

    public class BinaryProblemFactory : IProblemFactory
    {
        private BinaryProblemConfiguration _config;
        private Random _random;
    
        public BinaryProblemFactory(BinaryProblemConfiguration config)
        {
            _config = config;
            // or you can use const seed here
            _random = new Random(DateTime.Now.Millisecond); 
        }
    
        public override Problem CreateProblem()
        {
            var x = GenerateValueInRange(_config.XRange);
            var y = GenerateValueInRange(_config.YRange);
            return new BinaryProblem(x, y);
        }
    
        private decimal GenerateValueInRange(Range<int> range)
        {
            return _random.Next(range.Min, range.Max);
        }
    }
    

    Factory creation:

    BinaryProblemConfiguration config = new BinaryProblemConfiguration();
    config.XRange = new Range<int>(0, 100);
    config.YRange = new Range<int>(-50, 50);
    
    IProblemFactory problemFactory = new BinaryProblemFactory(config);
    

    Pass created problem factory somewhere as IProblemFactory:

    Problem problem = problemFactory.CreateProblem();
    

    Also there no special need for configuration object. I think that creator of product should have knowledge how to create product. So I’d rather go with properties XRange and YRange added to factory:

     BinaryProblemFactory binaryProblemFactory = new BinaryProblemFactory();
     binaryProblemFactory.XRange = new Range<int>(0, 100);
     binaryProblemFactory.YRange = new Range<int>(-50, 50);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm not sure how best to describe this, or the best title, so bear
(Not sure if this title is the best description...) Hi all. I need a
Not sure what the best title would be for this question, or even if
I'm not sure how to put this best into a title, but this is
I'm not sure how best to word the Title of this, so if someone
I'm not sure if this is the best way to do it, but I
I'm not entirely sure if this is the best way to word it, however,
I'm not sure how to best explain this, so this may be a bit
So I'm not sure what the best way to accomplish this is, but basically
I am not sure if I am going about this the best way, but

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.