I have an object person that I’m using in several methods on the front-end. How do I do that best? create new instance every time? or do public? or something else? seems pretty basic question to me.
public class Employee
{
public void DeleteEmployee(int employeeId)
{
......
}
public void UpdateEmployee(int employeeId)
{
......
}
}
and then on the front-end(that’s how I do it):
protected void OnDelete(object sender, EventArgs e)
{
Employee emp = new Employee();
emp.DeleteEmployee(empId);
}
protected void OnUpdate(object sender, EventArgs e)
{
Employee emp = new Employee();
emp.UpdateEmployee(empId);
}
I think what you are looking for is what I would call an Employee Manager. Two popular ways to do this are to create a seperate EmployeeManager object with static methods to perform the operations, or add the static methods to the Employee object. There is some debate as to which method is the preferred one. However, the common thought process is that the Employee instance should not know anything about how it is persisted. So the results would look like either…
or…