I am writing a class with member variables. I want to define default values for these fields and have to ability to override them with custom set values. I want to create some sort of class or struct in order to hold the data for these variables. I want someone using the class to have the ability to define all of the variables, or if they don't then the fields will be set to defaults (which I would define). Not sure of cleanest way to do this. This is what I have in mind but I'm not sure if I can do better:
public class ReportPageParams
{
public float Width { get; private set; }
public float Height { get; private set; }
public float LeftMargin { get; private set; }
public float RightMargin { get; private set; }
public float TopMargin { get; private set; }
public float BottomMargin { get; private set; }
//Constructor
ReportPageParams(float pWidth, pHeight)
{
Width = 52f
Height = 52f
//...
}
}
public class ReportPage
{
//same fields as ReportPageParams plus some more
private float _width, _height;
private float _leftMargin;
private float _rightMargin;
//...
ReportPage(ReportPageParams pCustomParams = null)
{
if (pCustomParams != null)
{
_width = pCustomParams.Width
_height = pCustomParams.Height
//...
}
else
{
//set fields to default values
}
}
}