c# - How to improve this design (pattern)? -


I am making a software for math problems. As you know, there are many types of mathematical problems.

In my software, some problems meet the XML file (repository) and can be generated by another factory (random number, you know).

For example, if I am adding binary problems, then if I select the first option then I may have a class where three files are found and select some of them. Or if I choose the second option, then I can generate problems randomly:

  x = random.Next (y, z); Y = Random Next (y, z); Return new binary probable (X, Y);  

So I have just developed this design, I think I have created a strategy pattern.

  Public Interface IProblemService {IEnumerable & lt; Problem & gt; GetProblems (); } Public Class Problem Service: IProblemService {Private Redoni IService Service; Public Issue Service (IService Service) {this.service = service; } Public IService Services {Received {Return Service; }} Public IEnumerable & lt; Problem & gt; GetProblems () {return.service.GetProblems (); }} / * ============================================== ======= * / Solid Category Public Interface IService {IEnumerable & lt; Problem & gt; GetProblems (); } // When I want to generate random problems with Public Intangible Square FactoryService: IService {public IEnumerable & lt; Problem & gt; GetProblems (); Public refinement (); } // When I want to get issues through an XML file public class repository service: IService {public abstract IEnumerable & lt; Problem & gt; GetProblems (); Submit Zero (IEnumerable & lt; Problems & gt; Problems); }   

In this service, I have kept the case as public, because I have to know that the service is a factory or store, in case it will be a repository, I will present some problems in the file. I do

I am not sure of the design, I think I am getting unnecessarily and it is not the best way to do it.

Can you give your app or idea to improve it?

Edit: What I mean is the first option:

  public IEnumerable & lt; Problem & gt; GetProblems () {if (model == zero) {model = new list & lt; Problem & gt; (); // dummy data. Model Add (New Simple Process () {ID = "1", expression = "8A · 2x5A · 10", Result 1 = 2}); Model Add (New Simple Process () {ID = "2", expression = "20 Ã 2 x 5 - 2", result1 = 48}); Model Add (New Simple Process () {ID = "3", expression = "15 Ã, 5 + 3", result1 = 6}); Model Add (New Simple Process () {ID = "4", expression = "6 + 4²²" - 8 - 2, result 1 = 6}); Model Add (new Simple Process () {id = "5", expression = "8 + 2x4", result1 = 40}); Model Add (New Simple Process () {id = "6", expression = "8 + 4 x (5-3)", result1 = 16}); Model Add (new Simple Process () {id = "7", expression = "8 - 3 + 5", result1 = 10}); // ...} return model; }    

I'm not sure why you have two different interfaces, Code> IProblemService and IService ; I feel like they do the same thing.

I will separate the generation of random problems ("factory" part) from the class that actually gives problems ("repository" part):

  public interface IProblemRepository {IEnumerable & lt; Problem & gt; LoadProblems (); } Public class XmlProblemRepository: IProblemRepository {...} Public Class InMemoryProblemRepository: IProblemRepository {Private Redonly IEnumerable & lt; Problem & gt; Problems; Public InMemoryProblemRepository (IEnumerable & lt; Problems & gt; Problems) {this.problems = problems; } Public IEnumerable & lt; Problem & gt; Load Problems () {Return problems; }} Public class Random Problephcture (Public InenMerable & lt; Problems & gt; GenerateProblems (int count) {...}}   

Then you can load with an XML file: < / P>

  repository = new XmlProblemRepository ("Problems XML");   

Or you can generate problems by using the factory and store them with in-store storage Can create source:

  factory = new random profilefactor (); Problems = factory. Generate problems (10); Repos Titri = new Inomerory Problem Repository (Problem);    

Comments