Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Interfaces

Interfaces

Scheduled Pinned Locked Moved C#
oophelp
5 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    deanoA
    wrote on last edited by
    #1

    Hi! Please help me with this. I want to make a program that inherits from two third party classes. (Let's just call it ClassA and ClassB) I know I cannot do multiple inheritance so I need to use interface. But I don't know how. Please help. "To teach is to learn twice"

    G A 2 Replies Last reply
    0
    • D deanoA

      Hi! Please help me with this. I want to make a program that inherits from two third party classes. (Let's just call it ClassA and ClassB) I know I cannot do multiple inheritance so I need to use interface. But I don't know how. Please help. "To teach is to learn twice"

      G Offline
      G Offline
      gonenb
      wrote on last edited by
      #2

      i found this site with excelent tutorials on c# this is chapter 7 , that teach abstract classes & interfaces http://www.programmersheaven.com/2/les\_csharp\_7\_p1

      D 1 Reply Last reply
      0
      • G gonenb

        i found this site with excelent tutorials on c# this is chapter 7 , that teach abstract classes & interfaces http://www.programmersheaven.com/2/les\_csharp\_7\_p1

        D Offline
        D Offline
        deanoA
        wrote on last edited by
        #3

        I have already read that site. It doesn't answer my question. Actually the problem here is that, the classes are THIRD PARTY CLASSES. It already has existing methods that I need to use. Thanks anyway. :) "To teach is to learn twice"

        R 1 Reply Last reply
        0
        • D deanoA

          I have already read that site. It doesn't answer my question. Actually the problem here is that, the classes are THIRD PARTY CLASSES. It already has existing methods that I need to use. Thanks anyway. :) "To teach is to learn twice"

          R Offline
          R Offline
          Randhir Sinha
          wrote on last edited by
          #4

          If the methods in the third party classes that you are interested in are public, then you do not need to use any inheritence, multiple or single. Simply use objects of these classes. Otherwise if the methods are protected, then subclass both the third party classes, yourself, and add public methods in the subclasses, that use the protected methods of your interest. Then use your subclasses, instead of the original third party classes. This is kind of a hack. In either case, you can avoid inheriting from those third party classes.

          1 Reply Last reply
          0
          • D deanoA

            Hi! Please help me with this. I want to make a program that inherits from two third party classes. (Let's just call it ClassA and ClassB) I know I cannot do multiple inheritance so I need to use interface. But I don't know how. Please help. "To teach is to learn twice"

            A Offline
            A Offline
            Alvaro Mendez
            wrote on last edited by
            #5

            Use inheritance for one class and containment for the other:

            class C : A // inherit from A
            {
            private B b; // contain B and add wrapper methods

            public void SomeMethodInB()
            {
            b.SomeMethod();
            }

            public int SomeOtherMethodInB()
            {
            return b.SomeOtherMethod();
            }

            ...
            }

            Regards, Alvaro


            Can I ask you a question?

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups