C# のクラスに推奨される明確なレイアウトはありますか?
これはレイアウトの質問の例です...
public class DinnerParty {
//>>>>should the const fields that are initiallised with a value be at the top?
private const int CostOfFoodPerPerson = 25;
//>>>>should the constructor always be placed near the top of the class?
public DinnerParty(int numberOfPeople, bool Health, bool fancyDecorations) {
NumberOfPeople = numberOfPeople;
this.fancyDecorations = fancyDecorations;
Health = healthyOption;
CalculateCostOfDecorations(fancyDecorations);
}
//>>>>backing private fields should always precede properties that use them?
private int numberOfPeople;
public int NumberOfPeople {
get {
return numberOfPeople;
}
set {
CalculateCostOfDecorations(fancyDecorations);
numberOfPeople = value;
}
}
//>>>>where do these fields go?
private bool fancyDecorations;
public decimal costOfBeveragePerPerson;
private bool healthyOption;
public bool HealthyOption{
set {
value = healthyOption;
if (healthyOption) {
costOfBeveragePerPerson = 5.0M;
} else {
costOfBeveragePerPerson = 20.0M;
}
}
}
//>>>>should methods be placed after the constructor and all properties?
public decimal costOfDecorations = 0;
void CalculateCostOfDecorations(bool fancy) {
if (fancy) {
costOfDecorations = (numberOfPeople * 15.0M) + 50.0M;
} else {
costOfDecorations = (numberOfPeople * 7.50M) + 30.0M;
}
}
public decimal CalculateCost(bool xfancy, bool xhealthyOption) {
decimal totalCost = (numberOfPeople * (CostOfFoodPerPerson + costOfBeveragePerPerson)) + costOfDecorations;
if (xhealthyOption) {
return totalCost * 0.95M;
} else {
return totalCost;
}
}
}