C
C#•3y ago
Hanami

Design

Hello, I decided to write a small program, but I ran into a design problem. The point is. There are 2 population groups Eastern and Western. There are 5 population levels in the western group, and 2 in the eastern group. The population consumes certain goods in a certain amount. Each next level consumes the same goods as the previous one + new goods. At the same time, the amount of consumption of the same goods by different levels of the population also differs. The task of the program is to read data from the process memory (I coped with this), then multiply the received quantity data by special consumption coefficients (which I also have), and then output. And now I have a question, and how best to organize the counting. There was an idea to create a class for each level, create a number field in it, then create fields for storing coefficients that would be defined in the class constructor. And then I don't know. There was an idea to create a get property for each multiplication and count them and immediately return the result. There was an idea to write a universal Calculate method, but the question arose as to how to initiate this method for each multiplication or immediately perform all multiplications in this method, but then it will need to be redefined. In general, help with this, please.
4 Replies
Anton
Anton•3y ago
does the calculation logic differ between levels? or is it just the coefficients that differ if it's just the coefficients, you could just make a struct with a field for each of the coefficients. then put these in an array, one for each level
Hanami
Hanami•3y ago
The logic of calculations for all levels and all products is the same, a simple multiplication of the population by a unique coefficient.
Anton
Anton•3y ago
well, if it's just a single coefficient, then it's even simpler. Just make an array of floats or whatever, holding a coefficient for each of the levels and then just index that array with the current level index when you calculate the stuff
Hanami
Hanami•3y ago
OK, thanks for the help🙃
Want results from more Discord servers?
Add your server