I am studying about OOP concepts. As I understood from the documents I have read, I wrote an example program for encapsulation concept in OOP. I pasted my code below. Is my concept about encapsulation is correct ?.
Default.aspx
<asp:Button ID="showBtn" Text="Show employee details." runat="server"/>
Default.aspx.cs
public partial class _Default : System.Web.UI.Page
{
Employee emp;
protected void Page_Load(object sender, EventArgs e)
{
emp = new Employee();
emp.SetEmployeeID(001);
emp.SetEmployeeSalary(5000);
emp.EmployeeName = "Rob";
emp.EmployeeAge = 26;
showBtn.Click += new EventHandler(showBtn_Click);
}
void showBtn_Click(object sender, EventArgs e)
{
emp.ShowEmployeeDetails();
}
}
Class Employee
class Employee
{
private int empId;
private int empSalary;
private string empName;
private int empAge;
public void SetEmployeeID(int id)
{
empId = id; //Mutator
}
public void SetEmployeeSalary(int sal)
{
empSalary = sal; //Mutator
}
public int GetEmployeeID()
{
return empId; //Accessor
}
public int GetEmployeeSalary()
{
return empSalary; //Accessor
}
public string EmployeeName
{
get { return empName; } //Accessor
set { empName = value; } //Mutator
}
public int EmployeeAge
{
get { return empAge; } //Accessor
set { empAge = value; } //Mutator
}
private void ShowDetails()
{
HttpContext.Current.Response.Write(this.GetEmployeeID() + " : " + this.EmployeeName + " : " + this.EmployeeAge + " : " + this.GetEmployeeSalary());
}
public void ShowEmployeeDetails()
{
ShowDetails();
}
}
My main doubt is about the way I called the ShowDetails() method in the Employee. Is this a good way to hide the method ShowDetails() ?.