I've already asked "Dealing with a large interface".
I have a further question regarding that situation. It was pointed out to me that I used a lot of getters and setters and so I broke encapsulation. I'm aware of this, but I can't really imagine how I would code this differently. All my getters seem natural to me - they expose information that I directly react on in the UI. How could it be improved in this way?
The code from the original question:
public interface ISystemSolver
{
// Configuration
int NumberBase { get; set; }
bool CaseSensitive { get; set; }
bool LeadingZeros { get; set; }
// State
IReadOnlyList<int> ForbiddenValues { get; }
IReadOnlyList<char> ForbiddenVariables { get; }
event EventHandler OnTooManyVariables;
bool AreThereTooManyVariables { get; }
// Variables
IEnumerable<Variable> Variables { get; }
void RemoveVariable(int index);
void AddVariable(char variable, int value);
// Equations
IEnumerable<Equation> Equations { get; }
void RemoveEquation(int index);
void AddEquation(string equation);
// Solving
IEnumerable<Solution> Solve();
}
EDIT: Usage of ForbiddenValues
and ForbiddenVariables
private void UpdateVariablesComboBox()
{
// Get the forbidden variables
var forbiddenVariables = _manager.ForbiddenVariables;
// Get the variables that are not forbidden
var items = _manager.Variables
.Where(c => !forbiddenVariables.Contains(c))
.Select(c => c.ToString())
.Cast<object>()
.ToArray();
// Clear the combo box
_variablesComboBox.Items.Clear();
// Update the combo box
_variablesComboBox.Items.AddRange(items);
}
private void UpdateValuesComboBox()
{
// Get the current number base
var currentBase = _manager.NumberBase;
// Get the forbidden values
var forbiddenValues = _manager.ForbiddenValues;
// Get possible values that are not forbidden
var items = Enumerable.Range(0, currentBase)
.Where(i => !forbiddenValues.Contains(i))
.Select(i => i.ToString())
.Cast<object>()
.ToArray();
// Clear the combo box
_valuesComboBox.Items.Clear();
// Update the combo box
_valuesComboBox.Items.AddRange(items);
}