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

I'm a fan of immutable objectsimmutable 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 DoctorTrust 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 DoctorTrust me - I'm a Doctor recommendsrecommends.

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.2k
  • 1
  • 39
  • 52

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;
    }
}