|
-
Mar 21st, 2002, 07:55 AM
#1
Thread Starter
Hyperactive Member
Interfaces...why? Please explain
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
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|