Work with multiple input parameters, multiple outputs

I need to do a complicated calculation. In my case, the most natural was to create a calculator class (abstracted using a strategy template).

To perform the calculation, the class must accept about 20 inputs, some of which are optional, some of which may change in the future, etc. After calling the Calculate () method for about 20, you need to output various variables.

There are several ways to achieve this.

  • Inputs passed as parameters to the calculation method
  • Inputs Passed Through Calculator Properties
  • Inputs wrapped in their own class are then passed to the Calculate () method.
  • Outputs returned by Calculate () wrapped in a class
  • The outputs filled with the parameter passed to the Calculate () method
  • The outputs obtained from the public properties of the Calculator, after Calculate () was called

There are all the pros and cons of all these methods. How do you do this?

UPDATE: Thanks for the feedback.

The purpose of this calculator is to generate a quote. Entries are things like customer address, interest rates, target profit, extra fees, product identifier, etc. The result includes a quote, actual profit, more fees, etc.

I went ahead and created the ICalculateInput and ICalculateOutput interfaces and their specific classes, and the system works very well. The Calculator class also inherits from the ICalculator interface (since the calculations used differ significantly depending on the company from which the product is obtained).

+3
10

" " " ". , , . , . , , ;

Result calculate(RequiredArgs requiredArgs) {
...
}

Result calculate(RequiredArgs requiredArgs, OptionalArgs optionalArgs) {
}

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

API. , , . , , .

- . .

+3

  • , , Calculate().
  • , Calculate(),

, , , . , , .

, -

- . , , "", .

+4

. , - , ..

, , - Composite. Java , , , , .

+1

, , 3-4

-, JavaScript:

var addUser = function (name,surname, age, add1, add2, telephone) {
    //do something
};

- :

var addUser = function (userDetails) {
    //Do something with userDetails.name etc...
};
//Then invoke the function by passing in an object:
var ud = {name : 'Andreas', surname : 'Grech', age : 20, add1 : 'bla', add2 : 'bla', telephone : 12343}; 
addUser(ud);

, , , ,

+1

, .

, , , , - Builder , .

+1

  • , Calculate

, 20 ... . , , Strategy, . , Calculate

+1

, #. , , ( ) .

, /.

0

, .net .

( i.e input/output) ( ).

. OleDBCommand/SQLCommand .net, /.

0

struct class, , .

0

, , , :

I would most likely use named parameters, but my choice language (Perl) supports order-independent parameters. If your not, then the transition to the object is the next best choice. To go through more than 2-3 parameters in a certain order (with a name or not), you just need to worry.

For output, I would most likely return an object if more than one value returns.

0
source

All Articles