Skip to main content
2 of 3
replaced http://codereview.stackexchange.com/ with https://codereview.stackexchange.com/

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;
    }
}
Jesse C. Slicer
  • 14.2k
  • 1
  • 39
  • 52