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 6319045
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T15:44:10+00:00 2026-05-24T15:44:10+00:00

Here is only an example from my code. I’m looking for a good way

  • 0

Here is only an example from my code. I’m looking for a good way to maintain my classes in order and following some OOP rules.

This my abstract class Problem:

public abstract class Problem<T> : IEquatable<T>
{
    public abstract int ResultCount { get; }
    protected abstract bool CheckTheAnswer(params object[] results);
    public abstract bool Equals(T other);
}

Below is one class which derives from Problem, Arithetic class contains all the necessary that contains in a math problem, and how to resolve it:

public enum Operations
{
    Addition, Subtraction, Multiplication, Division
}

public class Arithmetic : Problem<Arithmetic>
{
    public decimal Number1
    {
        get;
        set;
    }

    public Operations Operation
    {
        get;
        set;
    }

    public decimal Number2
    {
        get;
        set;
    }

    public override int ResultCount
    {
        get { return 1; }
    }

    protected override bool CheckTheAnswer(params object[] results)
    {
        if (results.Length != ResultCount)
            throw new ArgumentException("Only expected " + ResultCount + " arguments.");

        decimal result = (decimal)results[0];

        switch (Operation)
        {
            case Operations.Addition:
                return Number1 + Number2 == result;
            case Operations.Subtraction:
                return Number1 - Number2 == result;
            case Operations.Multiplication:
                return Number1 * Number2 == result;
            case Operations.Division:
                return Number1 / Number2 == result;
            default:
                throw new Exception("Operator unexpected");
        }
    }

    public override bool Equals(Arithmetic other)
    {
        if (other == null)
            return false;

        return this.Number1 == other.Number1 && Number2 == other.Number2;
    }
}

public class Addition : Arithmetic
{
    public Addition(decimal addend1, decimal addend2)
        : base()
    {
        Number1 = addend1;
        Number2 = addend2;
        Operation = Operations.Addition;
    }
}

// Subtraction, Multiplication and Divison here

Then I have another class which generate an Arithmetic problem, it receives a Tuple where contains some properties that indicates the conditions

interface IProblemFactory<T> where T : Problem<T>
{
    T Create();
}

public class ArithmeticProblemFactory : IProblemFactory<Arithmetic>
{
    private Tuple<Operations, Range, Range> _condition;

    public ArithmeticProblemFactory(Tuple<Operations, Range, Range> condition)
    {
        this._condition = condition;
    }

    public Arithmetic Create()
    {
        Operations operation = _condition.Item1;
        decimal a = _condition.Item2.GetNumber();
        decimal b = _condition.Item3.GetNumber();

        switch (operation)
        {
            case Operations.Addition:
                return new Addition(a, b);
            case Operations.Subtraction:
                return new Subtraction(a, b);
            case Operations.Multiplication:
                return new Multiplication(a, b);
            case Operations.Division:
                return new Division(a, b);
            default:
                throw new Exception("Operator unexpected");
        }
    }
}

The thing is… I need to have more properties, like Result (in Arithmetic class only needs 1, in comparison 2 numbers we need two properties result), problem number, time (seconds) to resolve the problem.

The question is, I don’t know where I should put these properties. One way it’ll be adding some of them in Problem class, or create another class something like these:

ArithmeticProblem

  • Problem Problem <– Here is Arithmetic class

  • Result

  • Time

  • Problem number

I only want to organize my classes as must be.
Thanks in advance.

  • 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-24T15:44:10+00:00Added an answer on May 24, 2026 at 3:44 pm

    You can have different classes for result and in your Arithmetic class accept result type as generic:

    public class Arithmetic < TResult> : ...
    

    and Addition can be as bellow:

    public class Addition : Arithmetic <decimal>
    ...
    

    but if the number of parameters (like result, time, …) are not fixed (dynamic) you can have a dictionary and store them in dictionary (their type) and write specific action and set them as value of dictionary.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Here is the example code from my web.xml <security-constraint> <display-name> change password</display-name> <web-resource-collection> <web-resource-name>change
There is a similar question here but it only covers some of the issues
Here's an sample code, where only the string object is released. NSString *nameOfFile =
This only happens in some IE's. Here: http://animactions.ca/Animactions/volet_entreprise.php You may notice that when you
Have a simple form (only extract fields here) but for some reason the JQserilization
I've noticed from here that the contents is only the header Revision 16532: /tags/3.3.2.SR1/samples/richfaces-demo/src/main/java/org/richfaces/demo/dataTableScroller
Here is my code, everything is working fine the only problem is with the
I am looking for a way to extract an icon from a .exe file
I have followed the onTouch example from google located here . However, I get
I am learning the NIO package. I refer the NioServer example from here .

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.