-
polimorfism
Hi,
I'm looking for information about the way of
redefine class parent methods in children. The instruction
implements seems to be used to implement polimorfism, but
i don't know how does it work. All the examples i've seen use
different names to codify children methods so, how can parent know
what's the method he needs to execute depending on child type?
thanks.
-
Re: polimorfism
The idea behind polymorphism is that classes can 'implement' a standard interface (or many different interfaces).
eg.
Class Animal - leave empty - it's just an interface
option Explicit
'
public Sub MakeNoise()
'
End Sub
Class Dog
option Explicit
'
Implements Animal
'
private Sub Animal_MakeNoise()
MsgBox "Woof"
End Sub
Class Mouse
option Explicit
'
Implements Animal
'
private Sub Animal_MakeNoise()
MsgBox "Eek!"
End Sub
Your 'parent' object can then instantiate these objects as follows :
Dim oMouse as Animal
Dim oDog as Animal
'
set oMouse = new Mouse
set oDog = new Dog
'
oMouse.MakeNoise
oDog.MakeNoise
Chris Eastwood
CodeGuru - the website for developers
http://www.codeguru.com/vb