Skip to main content
Code Review

Return to Answer

broken link fixed, cf. https://meta.stackoverflow.com/a/406565/4751173
Source Link

I'm a fan of immutable objects immutable objects for their various benefits. Below is an example of how to make your Ingredient class immutable. Similar techniques can be made to your Formula class. I also highly recommend not using ArrayList in favor of a generic List<Ingredient> as Trust me - I'm a Doctor Trust me - I'm a Doctor recommends.

sealed class Ingredient
{
 private readonly string name;
 private readonly decimal percentage;
 private readonly bool isFlour;
 private readonly decimal? weight;
 public string Name { get { return this.name; } }
 public decimal Percentage { get { return this.percentage; } }
 public bool IsFlour { get { return this.isFlour; } }
 public decimal? Weight { get { return this.weight; } }
 public Ingredient(string _Name, decimal _Percent, bool _IsFlour, decimal? _Weight)
 {
 this.name = _Name;
 this.percentage = _Percent;
 this.isFlour = _IsFlour;
 this.weight = _Weight;
 }
}

I'm a fan of immutable objects for their various benefits. Below is an example of how to make your Ingredient class immutable. Similar techniques can be made to your Formula class. I also highly recommend not using ArrayList in favor of a generic List<Ingredient> as Trust me - I'm a Doctor recommends.

sealed class Ingredient
{
 private readonly string name;
 private readonly decimal percentage;
 private readonly bool isFlour;
 private readonly decimal? weight;
 public string Name { get { return this.name; } }
 public decimal Percentage { get { return this.percentage; } }
 public bool IsFlour { get { return this.isFlour; } }
 public decimal? Weight { get { return this.weight; } }
 public Ingredient(string _Name, decimal _Percent, bool _IsFlour, decimal? _Weight)
 {
 this.name = _Name;
 this.percentage = _Percent;
 this.isFlour = _IsFlour;
 this.weight = _Weight;
 }
}

I'm a fan of immutable objects for their various benefits. Below is an example of how to make your Ingredient class immutable. Similar techniques can be made to your Formula class. I also highly recommend not using ArrayList in favor of a generic List<Ingredient> as Trust me - I'm a Doctor recommends.

sealed class Ingredient
{
 private readonly string name;
 private readonly decimal percentage;
 private readonly bool isFlour;
 private readonly decimal? weight;
 public string Name { get { return this.name; } }
 public decimal Percentage { get { return this.percentage; } }
 public bool IsFlour { get { return this.isFlour; } }
 public decimal? Weight { get { return this.weight; } }
 public Ingredient(string _Name, decimal _Percent, bool _IsFlour, decimal? _Weight)
 {
 this.name = _Name;
 this.percentage = _Percent;
 this.isFlour = _IsFlour;
 this.weight = _Weight;
 }
}
replaced http://codereview.stackexchange.com/ with https://codereview.stackexchange.com/
Source Link

I'm a fan of immutable objects for their various benefits. Below is an example of how to make your Ingredient class immutable. Similar techniques can be made to your Formula class. I also highly recommend not using ArrayList in favor of a generic List<Ingredient> as Trust me - I'm a Doctor Trust me - I'm a Doctor recommends recommends.

sealed class Ingredient
{
 private readonly string name;
 private readonly decimal percentage;
 private readonly bool isFlour;
 private readonly decimal? weight;
 public string Name { get { return this.name; } }
 public decimal Percentage { get { return this.percentage; } }
 public bool IsFlour { get { return this.isFlour; } }
 public decimal? Weight { get { return this.weight; } }
 public Ingredient(string _Name, decimal _Percent, bool _IsFlour, decimal? _Weight)
 {
 this.name = _Name;
 this.percentage = _Percent;
 this.isFlour = _IsFlour;
 this.weight = _Weight;
 }
}

I'm a fan of immutable objects for their various benefits. Below is an example of how to make your Ingredient class immutable. Similar techniques can be made to your Formula class. I also highly recommend not using ArrayList in favor of a generic List<Ingredient> as Trust me - I'm a Doctor recommends.

sealed class Ingredient
{
 private readonly string name;
 private readonly decimal percentage;
 private readonly bool isFlour;
 private readonly decimal? weight;
 public string Name { get { return this.name; } }
 public decimal Percentage { get { return this.percentage; } }
 public bool IsFlour { get { return this.isFlour; } }
 public decimal? Weight { get { return this.weight; } }
 public Ingredient(string _Name, decimal _Percent, bool _IsFlour, decimal? _Weight)
 {
 this.name = _Name;
 this.percentage = _Percent;
 this.isFlour = _IsFlour;
 this.weight = _Weight;
 }
}

I'm a fan of immutable objects for their various benefits. Below is an example of how to make your Ingredient class immutable. Similar techniques can be made to your Formula class. I also highly recommend not using ArrayList in favor of a generic List<Ingredient> as Trust me - I'm a Doctor recommends.

sealed class Ingredient
{
 private readonly string name;
 private readonly decimal percentage;
 private readonly bool isFlour;
 private readonly decimal? weight;
 public string Name { get { return this.name; } }
 public decimal Percentage { get { return this.percentage; } }
 public bool IsFlour { get { return this.isFlour; } }
 public decimal? Weight { get { return this.weight; } }
 public Ingredient(string _Name, decimal _Percent, bool _IsFlour, decimal? _Weight)
 {
 this.name = _Name;
 this.percentage = _Percent;
 this.isFlour = _IsFlour;
 this.weight = _Weight;
 }
}
Source Link
Jesse C. Slicer
  • 14.5k
  • 1
  • 40
  • 54

I'm a fan of immutable objects for their various benefits. Below is an example of how to make your Ingredient class immutable. Similar techniques can be made to your Formula class. I also highly recommend not using ArrayList in favor of a generic List<Ingredient> as Trust me - I'm a Doctor recommends.

sealed class Ingredient
{
 private readonly string name;
 private readonly decimal percentage;
 private readonly bool isFlour;
 private readonly decimal? weight;
 public string Name { get { return this.name; } }
 public decimal Percentage { get { return this.percentage; } }
 public bool IsFlour { get { return this.isFlour; } }
 public decimal? Weight { get { return this.weight; } }
 public Ingredient(string _Name, decimal _Percent, bool _IsFlour, decimal? _Weight)
 {
 this.name = _Name;
 this.percentage = _Percent;
 this.isFlour = _IsFlour;
 this.weight = _Weight;
 }
}
lang-cs

AltStyle によって変換されたページ (->オリジナル) /