I'm working over project for my studies. It's a simple program about brewing coffee. I'm thinking about solution for showing single parameter in GUI.
I have a source brew parameter class:
public abstract class CoffeeParam { /* It's empty */ }
public class CoffeeParam<T> : CoffeeParam, INotifyPropertyChanged
{
public string ParamName { get => _paramName; set { _paramName = value; InvokePropertyChanged(); } }
public T Value { get => _value; set { _value = value; InvokePropertyChanged(); } }
public string ParamUnit { get => _paramUnit; set { _paramUnit = value; InvokePropertyChanged(); } }
private bool IsDescription { get => _isDescription; set { _isDescription = value; InvokePropertyChanged(); } }
private bool _isDescription;
private T _value;
private string _paramName;
private string _paramUnit;
#region PropertyChanged
private void InvokePropertyChanged([CallerMemberName]string propName = "")
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propName));
}
public event PropertyChangedEventHandler PropertyChanged;
#endregion
}
And the GUI class, where I try to reveal the type of CoffeeParam
:
public class MyUserControl1 : UserControl
{
public MyUserContro1(CoffeeParam coffeeParam)
{
Control cntr = null;
if (coffeeParam is CoffeeParam<double>)
{
// creating controls for double input
} else if (coffeeParam is CoffeeParam<int>)
{
// creating controls for int input
}
// rest of init code
}
}
An important thing is that the CoffeeParam<type>
may be almost everything (date, time, custom class).
My question is: How can I organize the GUI code to make it's close for modifications and open for extensions?
Actually, new param is forcing edition of the GUI class.
...
in your code and the close-vote for the same reason. \$\endgroup\$