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. multi inh

multi inh

Scheduled Pinned Locked Moved C#
question
6 Posts 5 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.
  • A Offline
    A Offline
    apadana_1989
    wrote on last edited by
    #1

    hi how can i multi inherit with interface please sample

    U L P 3 Replies Last reply
    0
    • A apadana_1989

      hi how can i multi inherit with interface please sample

      U Offline
      U Offline
      unknowndentified10111
      wrote on last edited by
      #2

      interface A { }
      public class B { }
      interface C : B, A
      {

      }

      You can only inherit one class, but you can inherit multiple interfaces. Just always put the class before the interfaces when inheriting it.

      1 Reply Last reply
      0
      • A apadana_1989

        hi how can i multi inherit with interface please sample

        L Offline
        L Offline
        Lost User
        wrote on last edited by
        #3

        Multiple inheritance is bad, mmkay? We prefer composition[^] :)

        Bastard Programmer from Hell :suss:

        B 1 Reply Last reply
        0
        • L Lost User

          Multiple inheritance is bad, mmkay? We prefer composition[^] :)

          Bastard Programmer from Hell :suss:

          B Offline
          B Offline
          BobJanova
          wrote on last edited by
          #4

          Multiple implementation (of interfaces) is fine, though. A class often actually is (the test for whether inheritance is appropriate) several things defined by simple (one aspect, ideally) interfaces, and implementing each of them makes sense. For example some sort of data model class could easily be an INotifyPropertyChanged, an IEnumerable<T>, and also some kind of IDataProvider interface within your own code. Or just look at the declaration of the collection classes in the framework.

          L 1 Reply Last reply
          0
          • A apadana_1989

            hi how can i multi inherit with interface please sample

            P Offline
            P Offline
            Pete OHanlon
            wrote on last edited by
            #5

            What you are talking about isn't multiple inheritance, it's multiple implementation. Take the following interfaces

            public interface IMyInterface
            {
            void DoSomething();
            }

            public interface IAnotherInterface
            {
            void DoSomethingElse();
            }

            Now, you have a class that needs to implement both of these. To do these, you add them to the class definition and then you provide an implementation for the interface methods. It looks like this:

            There you go - you have now implemented two interfaces in the same class.

            Forgive your enemies - it messes with their heads

            My blog | My articles | MoXAML PowerToys | Mole 2010 - debugging made easier - my favourite utility

            1 Reply Last reply
            0
            • B BobJanova

              Multiple implementation (of interfaces) is fine, though. A class often actually is (the test for whether inheritance is appropriate) several things defined by simple (one aspect, ideally) interfaces, and implementing each of them makes sense. For example some sort of data model class could easily be an INotifyPropertyChanged, an IEnumerable<T>, and also some kind of IDataProvider interface within your own code. Or just look at the declaration of the collection classes in the framework.

              L Offline
              L Offline
              Lost User
              wrote on last edited by
              #6

              BobJanova wrote:

              Multiple implementation (of interfaces) is fine, though.

              Multiple inheritance isn't even possible. Yes, you can implement multiple interfaces, but please don't use them to create an object that simply "binds" a few objects together; that's when a composition would be preferable. The question being phrased as it is, I'd guess that he's trying to combine an IEmployee and a IManager. ..thanks for the reminder though :)

              Bastard Programmer from Hell :suss:

              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