visualsander
Mar 21st, 2002, 06:55 AM
Hi group
I'm currently buzzy trying to understand interfaces and why I should use them.
I've come across an example explaining interfaces but I don't see why I need the interface.
Here's the example in short:
I have an interface named:IncreaseSalary
I have 3 classes:
CSupervisor
CStaff
CManager
They all implement the same interface (IncreaseSalary) however the result of IncreaseSalary is different for all 3 classes, that is:
CSupervisor.IncreaseSalary raises the salary with 5 %
CStaff.IncreaseSalary raises the salary with 3 %
CManager.IncreaseSalary raises the salary with 2 %
This is code for the client:
Dim emp as IEmployee
Select Case UserInput
case "Manager"
Set emp = New Cmanager
case "Supervisor"
Set emp = New CSupervisor
case "Staff"
Set emp = New CStaff
End Select
'pay the employee
emp.IncreaseSalary
So far it's clear. What I don't get is why I need to use the interface. Can't I just create the Method's in the 3 classes? That way i do not need the interface?!?! What am I missing?
Please help me out.
Regards,
Sander
I'm currently buzzy trying to understand interfaces and why I should use them.
I've come across an example explaining interfaces but I don't see why I need the interface.
Here's the example in short:
I have an interface named:IncreaseSalary
I have 3 classes:
CSupervisor
CStaff
CManager
They all implement the same interface (IncreaseSalary) however the result of IncreaseSalary is different for all 3 classes, that is:
CSupervisor.IncreaseSalary raises the salary with 5 %
CStaff.IncreaseSalary raises the salary with 3 %
CManager.IncreaseSalary raises the salary with 2 %
This is code for the client:
Dim emp as IEmployee
Select Case UserInput
case "Manager"
Set emp = New Cmanager
case "Supervisor"
Set emp = New CSupervisor
case "Staff"
Set emp = New CStaff
End Select
'pay the employee
emp.IncreaseSalary
So far it's clear. What I don't get is why I need to use the interface. Can't I just create the Method's in the 3 classes? That way i do not need the interface?!?! What am I missing?
Please help me out.
Regards,
Sander