I got a class that I made static, but is it a bad option? Should it be a non static class?
I want to set two values in my class.
Is there any chance when you give properties values that there will be some kind of conflict when setting them and when getting them? If another user have the same target.
I got a page that calling this class. One user hits the page and this happens.
- Set the properties for the calculation
- Run the void to calculate two properties
- "Maybe some other functions runs and take some time"
- Get the value of the two properties
But what if another user hits the page and sets other values and make either the first user's value incorrect. I guess that's possible?
Some other options I thought of is to either
- Send all properties into the void as arguments and return a new class with my two values I need. (Not store them as a static property that could be changed by another user before it got used).
- Create a new class with the properties (perhaps called BreakTime). Send that into the void as one argument. Return it, calculated.
- Or you tell me what the best option is! :)
Here how it looks:
public static class BreakTimeCalculator
{
public static int BreakFromSec { get; private set; }
public static int BreakUntilSec { get; private set; }
public static int CustomBreakSec { get; set; }
public static int FromSec { get; set; }
public static int UntilSec { get; set; }
public static int Equlizer { get; set; }
public static void CalculateBreakFromAndBreakeUntil()
{
var taskLength = UntilSec - FromSec;
var middleOfTask = FromSec + (taskLength / 2);
var secondsToMoveLeft = middleOfTask % 300;
var amountEqualizers = CustomBreakSec / Equlizer;
var fiftyFifty = amountEqualizers % 2 == 0;
var leftSideEqualizers = fiftyFifty ? amountEqualizers / 2 : (amountEqualizers / 2) + 1;
BreakFromSec = middleOfTask - secondsToMoveLeft - (leftSideEqualizers * Equlizer);
BreakUntilSec = BreakFromSec + CustomBreakSec;
}
}
Aucun commentaire:
Enregistrer un commentaire