I’m working on a Laravel project for engineers. The software calculates the stability and pressure for specific wooden connections.
As you can imagine, depending on the connection, there are many calculations with many values to be done.
First, there was the approach make one calculation function / method for one connection type (inside the connection type class), where all neccessary fields are calculated.
Then it came up to my mind, to create a method to calculate each value seperately:
public function calculateConnection($connectionValues) {
$connection->a = $this->getAValue($connectionValues);
$connection->b = $this->getBValue($connectionValues);
...
}
public function getAValue($connectionValues) {
return ...
}
public function getBValue($connectionValues) {
return ...
}
I have a much better overview about the specific values, when creating a function for each value instead of calculating everything in one method, but the issue is, that the values are depending on each other. So value a
is needed to calculate b
.
So all methods need to be called in the correct order. Of course, I can do a check, if a
is already been calculated, before doing the calculation of b
, but this will blow up the code so much.
I’m interested, what is best-practice in this kind of situation.