COM and Polymorphism

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Matthew Page
    New Member
    • Jul 2007
    • 36

    COM and Polymorphism

    From what I've read, it isn't possible to have true polymorphism (well... function overloading...) using COM functions. I wanted to double check here to find out if there is a hack/work-around/bit-of-magic that can be done to mimic function overloading.

    If not, then I will just have to use different function names.
  • weaknessforcats
    Recognized Expert Expert
    • Mar 2007
    • 9214

    #2
    Yes. When you implement a COM interface, you are implementing a set of pure virtual functions. Check your IDL. There you see the word interface which is a #define of a struct.

    The only (gag) problem is that you need to typecast your object to the interface type by using IUnknown::Query Interface.

    All polymorphism requires is substitution of a specific object for a general object. It does not specify the rules for the substitution. Maybe it's a typecast. Maybe a duck. Maybe a Lishkov substitution.

    Comment

    • Matthew Page
      New Member
      • Jul 2007
      • 36

      #3
      Originally posted by weaknessforcats
      Yes. When you implement a COM interface, you are implementing a set of pure virtual functions. Check your IDL. There you see the word interface which is a #define of a struct.

      The only (gag) problem is that you need to typecast your object to the interface type by using IUnknown::Query Interface.

      All polymorphism requires is substitution of a specific object for a general object. It does not specify the rules for the substitution. Maybe it's a typecast. Maybe a duck. Maybe a Lishkov substitution.

      Ahhh yes... Interesting question... (Have you seen the movie IQ?)

      Comment

      • JosAH
        Recognized Expert MVP
        • Mar 2007
        • 11453

        #4
        Originally posted by Matthew Page
        Ahhh yes... Interesting question... (Have you seen the movie IQ?)
        The reply wasn't silly at all: design a bare bones DAO (Data Access Object) that
        handles your COM object directly. Implement wrapper classes around that DAO
        class that implement all the method overloading you want/need.

        kind regards,

        Jos

        Comment

        • Matthew Page
          New Member
          • Jul 2007
          • 36

          #5
          Originally posted by JosAH
          The reply wasn't silly at all: design a bare bones DAO (Data Access Object) that
          handles your COM object directly. Implement wrapper classes around that DAO
          class that implement all the method overloading you want/need.

          kind regards,

          Jos
          In the movie IQ, a smart but uneducated guy tries to pass himself off (with the help of Albert Einstein) as a super genius physicist to a very smart physicist girl. The guy asks Albert what to say if she asks him a question he can't answer. The response was something to the effect of "Just look thoughful and say, "Hmmm Interesting question." I didn't understand what he was trying to say. (Happens to me WAY to often...) So I put that silly reply in there while I thought about what he was saying.

          The solution that you mentioned will work I think. And it also solves one or two other problems I was preparing to tackle with this project.

          Thanks for the help.

          - Matt

          Comment

          • weaknessforcats
            Recognized Expert Expert
            • Mar 2007
            • 9214

            #6
            Originally posted by Matthew Page
            So I put that silly reply in there while I thought about what he was saying.
            I have done the same thing myself. Usually in a classroom where my example won't compile and I can't see the error. So I ask the class: "Can anyone tell me what the compiler is saying??". I can ask several students all the while I am racking my brain for an answer. By the time the class runs out of ideas, I have found the problem.

            So, was Einstein really smart or did he just pose interesting questions?

            Comment

            • JosAH
              Recognized Expert MVP
              • Mar 2007
              • 11453

              #7
              Originally posted by weaknessforcats
              So, was Einstein really smart or did he just pose interesting questions?
              He was really smart; I mean he attended every single Saturday night party at
              'good time Johny's' (John von Neumann) place and never got thrown out ;-)

              kind regards,

              Jos

              Comment

              • weaknessforcats
                Recognized Expert Expert
                • Mar 2007
                • 9214

                #8
                Originally posted by JosAH
                never got thrown out ;-)
                So you are saying he was un-exceptional.

                Comment

                • JosAH
                  Recognized Expert MVP
                  • Mar 2007
                  • 11453

                  #9
                  Originally posted by weaknessforcats
                  So you are saying he was un-exceptional.
                  Read "who took Einstein's place" for all the gory details ;-)

                  kind regards,

                  Jos

                  Comment

                  Working...