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

  • Home
  • SEARCH
  • 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 8206183
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T08:34:59+00:00 2026-06-07T08:34:59+00:00

I’m creating a software for math problems. As you know, there are many types

  • 0

I’m creating a software for math problems. As you know, there are many types of math problems.

In my software, some problems are gotten from an Xml file (repository) and anothers can be generated by a factory (random numbers, you know).

For example, if I’m creating binary problems as additions, if I choose the first option I can have a class where get thre file and choose some of them. Or if I choose the second one, I can generate the problems as random:

x = random.Next(y, z);
y = random.Next(y, z);

return new BinaryProblem(x, y);

Something like that.

So I’ve developed right now this design, I guess I’ve builded a strategy pattern.

public interface IProblemService
{
    IEnumerable<Problem> GetProblems();
}

public class ProblemService : IProblemService
{
    private readonly IService service;

    public ProblemService(IService service)
    {
        this.service = service;
    }

    public IService Service
    {
        get { return service; }
    }

    public IEnumerable<Problem> GetProblems()
    {
        return this.service.GetProblems();
    }
}

/* =====================================================*/
CONCRETE CLASSES

public interface IService
{
    IEnumerable<Problem> GetProblems();
}

// When I want to generate random problems
public abstract class FactoryService : IService
{
    public IEnumerable<Problem> GetProblems();
    public abstract Generate();
}

// When I want to get problems through a XML file
public class RepositoryService : IService
{
    public abstract IEnumerable<Problem> GetProblems();
    void Submit(IEnumerable<Problem> problems);
}

In the service I put IService as public because, I need to know if the service is a factory or repository. In the case this will be a repository, I’d submit some problems to the file.

I’m not convinced of the design. I guess I’m being redundant and this is not the best way to do it.

Can you give your opinnion or ideas to improve it?

EDIT:
What I meant with the first option is:

    public IEnumerable<Problem> GetProblems()
    {
        if (model == null)
        {
            model = new List<Problem>();

            // Dummy Data.
            model.Add(new SimplifyProblem() { Id = "1", Expression = "8 ÷ 2 x 5 ÷ 10", Result1 = 2 });
            model.Add(new SimplifyProblem() { Id = "2", Expression = "20 ÷ 2 x 5 - 2", Result1 = 48 });
            model.Add(new SimplifyProblem() { Id = "3", Expression = "15 ÷ 5 + 3", Result1 = 6 });
            model.Add(new SimplifyProblem() { Id = "4", Expression = "6 + 4² ÷ 8 - 2", Result1 = 6 });
            model.Add(new SimplifyProblem() { Id = "5", Expression = "8 + 2 x 4", Result1 = 40 });
            model.Add(new SimplifyProblem() { Id = "6", Expression = "8 + 4 x (5 - 3)", Result1 = 16 });
            model.Add(new SimplifyProblem() { Id = "7", Expression = "8 - 3 + 5", Result1 = 10 });
            // ...
        }

        return model;
    }
  • 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-06-07T08:35:00+00:00Added an answer on June 7, 2026 at 8:35 am

    I’m not sure why you have two separate interfaces, IProblemService and IService; to me, it seems like they do the same thing.

    I would separate the generation of random problems (the “factory” part) from the class that actually returns the problems (the “repository” part):

    public interface IProblemRepository {
      IEnumerable<Problem> LoadProblems();
    }
    
    public class XmlProblemRepository : IProblemRepository {
      ...
    }
    
    public class InMemoryProblemRepository : IProblemRepository {
      private readonly IEnumerable<Problem> problems;
    
      public InMemoryProblemRepository(IEnumerable<Problem> problems) {
        this.problems = problems;
      }
    
      public IEnumerable<Problem> LoadProblems() {
        return problems;
      }
    }
    
    public class RandomProblemFactory {
      public IEnumerable<Problem> GenerateProblems(int count) {
        ...
      }
    }
    

    Then you can either load from an XML file:

    repository = new XmlProblemRepository("problems.xml");
    

    or you can generate problems using the factory and source them from an in-memory repository:

    factory = new RandomProblemFactory();
    problems = factory.GenerateProblems(10);
    repository = new InMemoryProblemRepository(problems);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have just tried to save a simple *.rtf file with some websites and
For some reason, after submitting a string like this Jack’s Spindle from a text
In my XML file chapters tag has more chapter tag.i need to display chapters
We are using XSLT to translate a RIXML file to XML. Our RIXML contains
Does anyone know how can I replace this 2 symbol below from the string
I'm parsing an XML file, the creators of it stuck in a bunch social
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function

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.