CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2

Thread: polimorfism

  1. #1
    Guest

    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.


  2. #2
    Join Date
    May 1999
    Location
    Oxford UK
    Posts
    1,459

    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured