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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T22:05:04+00:00 2026-05-10T22:05:04+00:00

I need to perform a complicated calculation. In my case it seemed most natural

  • 0

I need to perform a complicated calculation. In my case it seemed most natural to create a Calculator class (abstracted using a strategy pattern).

To perform the calculation the class needs to accept about 20 inputs, some of which are optional, some of which could change in the future etc. Once the Calculate() method is called, about 20 different variables need to be outputted.

There are a number of ways this can be achieved.

  • Inputs passed in as parameters to a calculate method
  • Inputs passed in through properties of the Calculator
  • Inputs wrapped up into their own class, then passed to Calculate() method.
  • Outputs returned by Calculate(), wrapped up in a class
  • Outputs populated into a parameter passed to the Calculate() method
  • Outputs retrieved from public properties of the Calculator, after Calculate() has been called

There are pros and cons to all these methods. How would you do it?

UPDATE: Thanks for the feedback.

The purpose of this calculator is to generate a quote. The inputs are things such as the customer’s address, interest rates, target profit, additional fees, product id etc The output includes the quote, the actual profit, more fees etc.

I have gone ahead and created ICalculateInput and ICalculateOutput interfaces and their concrete classes, and the system works very well now. The Calculator class also inherits from an ICalculator interface (as the calculations involved differ enormously depending on the company the product is sourced from).

  • 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. 2026-05-10T22:05:05+00:00Added an answer on May 10, 2026 at 10:05 pm

    Most people suggest using a ‘Parameter Class’, and a ‘Result Class’. I agree with this approach, but it seems to me that your parameters fall into several categories. Perhaps you could create a parameter class for the required parameters, and a separate parameter class for the optional parameters or groups of optional parameters. This way, you could create different methods depending on what kind of calculation you require;

    Result calculate(RequiredArgs requiredArgs) { ... }  Result calculate(RequiredArgs requiredArgs, OptionalArgs optionalArgs) { }  Result calculate(RequiredArgs requiredArgs, OptionalArgs optionalArgs, OtherOptionalArgs oOpitonalArgs) { } 

    This will make your API easier to use. If you don’t want to create classes for the different groups, you could also use Maps, but this will require more validation code in the calculation engine. Normally I would prefer parameter classes, but would have to know more about your particular problem to be decisive.

    I would not store the calculation result in the calculation engine itself, because of thread safety and object reusability. It’s much easier to maintain code that is stateless.

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

Sidebar

Related Questions

I need to perform a find and replace using XSLT 1.0 which is really
The Problem : Object models built using an ORM often need to perform multiple
I need to perform multiple operations on an Image, for example, I need to
I need to perform a few checks (enable or disable a label elsewhere on
I need to perform an action after a session times out. However I have
I need to perform operations on Lua tables from C where the tables are
I need to perform some operations on all folders within a file share which
I need to perform update/insert simultaneously changing structure of incoming data. Think about Shops
We need to perform the following operation in our database : There is a
I need to perform lots of evaluations of the form X(:,i)' * A *

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.