次のコードでは、内部ステータス フラグを使用する対象がわかりません: (C#)
// internal status flag
private int status = 0;
// status constants
private const int AMOUNT_SET = 1;
private const int RATE_SET = 2;
private const int PERIODS_SET = 4;
private const int ALL_SET = AMOUNT_SET | RATE_SET | PERIODS_SET;
public double LoanAmount
{
get
{
return this.loanAmount;
}
set
{
this.loanAmount = Math.Abs(value); //taking the absolute value of the user input to ensure getting positive values
this.status |= AMOUNT_SET;
CalcPayment(); //check if the method can calculate yet
}
}
public double InterestRate
{
get
{
return this.interestRate;
}
set
{
this.interestRate = Math.Abs(value);
if (this.interestRate >= 1)
this.interestRate /= 100; // if entered as a percent, convert to a decimal
this.status |= RATE_SET;
CalcPayment();
}
}
public int Periods
{
get
{
return this.periods;
}
set
{
this.periods = Math.Max(Math.Abs(value), 1);
this.status |= PERIODS_SET;
CalcPayment();
}
}
public double MonthlyPayment
{
get
{
return this.monthlyPayment;
}
}
public override string ToString()
{
return "\n\tThis is a loan of " + this.loanAmount.ToString("c") + " at " + this.interestRate.ToString("p") +
" interest for " + this.periods.ToString() + " months,\n\t\twith a monthly payment of " +
this.monthlyPayment.ToString("c") + ".";
}
private void CalcPayment()
{
if (this.status == ALL_SET)
{
double periodicInterestRate = interestRate / 12;
double compound = Math.Pow((1 + periodicInterestRate), periods);
this.monthlyPayment = this.loanAmount * periodicInterestRate * compound / (compound - 1);
}
}
では、なぜ status フラグを使用したのでしょうか? ありがとう