I've been reading up on different design patterns, mainly MVP and different adaptions of this design pattern / architecture.
Now, I've decided to have a little play with my own ideas, the main outcome separating the user view, from the actual modelling which does all the data changes.
The example is simple, the user is given three radio buttons to select from
- Employee One
- Employee Two
- Employee Three
When these radio buttons are selected it changes a datagrid view with three columns
- Firstname
- Lastname
- Age
My form code has three event driven functions, radioButton_checkChanged
.
To start with, I programatically make some new employees: (Ignore the spelling mistake!)
string[] employeeArray = new string[3];
employeeData emplyeeOne = new employeeData("Bob", "Smith", "21");
employeeData emplyeeTwo = new employeeData("John", "Brown", "56");
employeeData emplyeeThree = new employeeData("Andy", "Guy", "28");
private void employeeOne_CheckedChanged(object sender, EventArgs e)
{
updateEmployee(emplyeeOne);
dataGridView1.Rows.Add(employeeArray);
}
private void employeeTwo_CheckedChanged(object sender, EventArgs e)
{
updateEmployee(emplyeeTwo);
dataGridView1.Rows.Add(employeeArray);
}
private void employeeThree_CheckedChanged(object sender, EventArgs e)
{
updateEmployee(emplyeeThree);
dataGridView1.Rows.Add(employeeArray);
}
employeeData
class (I've tried to go for encapsulation on this):
public class employeeData
{
private string classFirstName { get; set; }
private string classLastName { get; set; }
private string classAge { get; set; }
public employeeData(string firstname, string lastname, string age)
{
classFirstName = firstname;
classLastName = lastname;
classAge = age;
}
public string[] updatePerson()
{
string[] data = new string[3];
data[0] = classFirstName;
data[1] = classLastName;
data[2] = classAge;
return data;
}
}
updateEmployee
function as seen earlier:
private void updateEmployee(employeeData who)
{
dataGridView1.Rows.Clear();
dataGridView1.Refresh();
employeeArray = who.updatePerson();
}
Am I on to the beginning of any major software design patterns here? Any adaptations and or improvements you can see to make my code a more robust?