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. The Lounge
  3. C# Limitation

C# Limitation

Scheduled Pinned Locked Moved The Lounge
questioncsharp
13 Posts 11 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.
  • Steve EcholsS Steve Echols

    The biggest limitation (compared to c++) for me is the lack of multiple inheritance. Interfaces just can't compete, because you end up duplicating tons of code that should be in a base class. At least that's my experience, which isn't much, because I gave up when my fingers started to hurt from cutting and pasting. :-D


    - S 50 cups of coffee and you know it's on!

    R Offline
    R Offline
    Roger Alsing 0
    wrote on last edited by
    #4

    Can you give a good example of when multiple inheritance is needed.. Beeing a C# geek that is used to single inheritance, I cant say that I suffer from the lack of multiple inheritance.. I was planning to make a MUD game once , thats one of the few times that I really really missed multiple inheritance.. SO any examples? (of scenarios , not code) http://www.puzzleframework.com

    R J realJSOPR 3 Replies Last reply
    0
    • R Roger Alsing 0

      Can you give a good example of when multiple inheritance is needed.. Beeing a C# geek that is used to single inheritance, I cant say that I suffer from the lack of multiple inheritance.. I was planning to make a MUD game once , thats one of the few times that I really really missed multiple inheritance.. SO any examples? (of scenarios , not code) http://www.puzzleframework.com

      R Offline
      R Offline
      Roger Alsing 0
      wrote on last edited by
      #5

      Oke the only real examples I can find myself is along the lines of: http://www.dotnetjunkies.com/WebLog/dotnetmi/archive/2005/10/27/133441.aspx[^] every example in that text reffered to inheriting general implementations of interfaces. eg inherit the implementation of IClonable , IComparable etc etc. and if that is the case, its not multiple inheritance we need, its mixins.. mixins does just that.. (and mixins do exist in the .net world , we support mixins in our NAspect framework.. but sure , native language support for them would be nice to) But what Im looking for is a valid example where you need to inherit two or more classes which are not default implementations of some sort of interfaces.. so, can anyone give me a real "aha!" example where multiple inheritance is the best way to go? http://www.puzzleframework.com

      1 Reply Last reply
      0
      • R Roger Alsing 0

        Can you give a good example of when multiple inheritance is needed.. Beeing a C# geek that is used to single inheritance, I cant say that I suffer from the lack of multiple inheritance.. I was planning to make a MUD game once , thats one of the few times that I really really missed multiple inheritance.. SO any examples? (of scenarios , not code) http://www.puzzleframework.com

        J Offline
        J Offline
        Jon Hulatt
        wrote on last edited by
        #6

        It's not hard to think of a scenario. Here's one: You've already got a class built than encapsulates the directshow samplegrabber callback stuff, and you want your windows form class to inherit that class. But the windows form class has to inherit from Form. And you can't have it both ways. So, you have to inherit from Form and implement ISampleGrabberCB, and copy/paste all the code from your sample grabber class. This, imho, goes against the fundamental principles of OO.

        using System.Beer;

        R 1 Reply Last reply
        0
        • J Jon Hulatt

          It's not hard to think of a scenario. Here's one: You've already got a class built than encapsulates the directshow samplegrabber callback stuff, and you want your windows form class to inherit that class. But the windows form class has to inherit from Form. And you can't have it both ways. So, you have to inherit from Form and implement ISampleGrabberCB, and copy/paste all the code from your sample grabber class. This, imho, goes against the fundamental principles of OO.

          using System.Beer;

          R Offline
          R Offline
          Roger Alsing 0
          wrote on last edited by
          #7

          yet again that would be inheriting an implementation of an interface.. see my above post.. http://www.puzzleframework.com

          1 Reply Last reply
          0
          • Steve EcholsS Steve Echols

            The biggest limitation (compared to c++) for me is the lack of multiple inheritance. Interfaces just can't compete, because you end up duplicating tons of code that should be in a base class. At least that's my experience, which isn't much, because I gave up when my fingers started to hurt from cutting and pasting. :-D


            - S 50 cups of coffee and you know it's on!

            W Offline
            W Offline
            WillemM
            wrote on last edited by
            #8

            There's a work-around for this issue. I made an implementation a couple of weeks ago which uses a separate class that implements the functionality that needs to be inherited from a second parent. Next I used an interface, implemented by both the class that implemented the stuff of the second parent and the class that needed the multiple inheritance. Voila, there you have it, no duplicate code and I can cast it to both the "parent" and the real parent. Though this works only if you need an interface from two parents and it's ok to use composition to expand the functionality of a class. Maybe I should write an article on this little trick, it looks neat ;P WM.
            What about weapons of mass-construction?

            R 1 Reply Last reply
            0
            • W WillemM

              There's a work-around for this issue. I made an implementation a couple of weeks ago which uses a separate class that implements the functionality that needs to be inherited from a second parent. Next I used an interface, implemented by both the class that implemented the stuff of the second parent and the class that needed the multiple inheritance. Voila, there you have it, no duplicate code and I can cast it to both the "parent" and the real parent. Though this works only if you need an interface from two parents and it's ok to use composition to expand the functionality of a class. Maybe I should write an article on this little trick, it looks neat ;P WM.
              What about weapons of mass-construction?

              R Offline
              R Offline
              Ryan Binns
              wrote on last edited by
              #9

              WillemM wrote:

              What about weapons of mass-construction?

              Have you seen any photos of Dubai recently? :~  I reckon they've got a few weapons of mass construction there.

              Ryan

              "Punctuality is only a virtue for those who aren't smart enough to think of good excuses for being late" John Nichol "Point Of Impact"

              1 Reply Last reply
              0
              • R Roger Alsing 0

                Can you give a good example of when multiple inheritance is needed.. Beeing a C# geek that is used to single inheritance, I cant say that I suffer from the lack of multiple inheritance.. I was planning to make a MUD game once , thats one of the few times that I really really missed multiple inheritance.. SO any examples? (of scenarios , not code) http://www.puzzleframework.com

                realJSOPR Offline
                realJSOPR Offline
                realJSOP
                wrote on last edited by
                #10

                Roger J wrote:

                Can you give a good example of when multiple inheritance is needed..

                Here's an example: We have a bunch of classes (maybe 30) derived from CFormView, and we had a requirement to add some common non-mfc code to all of the those classes. We coonsidered creating a new base class and changing a whole crap-load of code to support it, but the possibility of breaking otherwise perfectly working code because of cut/paste mistakes gave us all the heebee-jeebies. I suggested the use of multiple-inheritance as long as the new base class isn't derived from CObject (MFC is real touchy about multiple inheritance where two or more base classes are derived from CObject), we could create a non-mfc class and add ", public CMyNewBaseClass" to each of our CFormview-derived class's declarations. We used the replace-in-files feature in VS2005, and the fix was completed in less than 5 minutes. The old code remained intact, and the new code was easily tested. Even better, we can add more stuff to the new class whenever we need to. Multiple-inheritance to the rescue. YMMV In all honesty, that's the first time I've used multiple inheritance in any app that wasn't a school project.

                "Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997
                -----
                "...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001

                1 Reply Last reply
                0
                • A alaquniabi

                  Hi All, I hope every one be in good Health. I want ask every c# programmer , what is limiation of C# languages? What is C# language Can do and what is Cannot Do? ala qunaibi :-O

                  C Offline
                  C Offline
                  Colin Angus Mackay
                  wrote on last edited by
                  #11

                  alaquniabi wrote:

                  I want ask every c# programmer , what is limiation of C# languages?

                  That would flood you with replies - Are you sure you can handle it?


                  Scottish Developers events: * .NET debugging, tracing and instrumentation by Duncan Edwards Jones and Code Coverage in .NET by Craig Murphy * Developer Day Scotland: are you interested in speaking or attending? My: Website | Blog

                  1 Reply Last reply
                  0
                  • A alaquniabi

                    Hi All, I hope every one be in good Health. I want ask every c# programmer , what is limiation of C# languages? What is C# language Can do and what is Cannot Do? ala qunaibi :-O

                    M Offline
                    M Offline
                    Marc Clifton
                    wrote on last edited by
                    #12

                    alaquniabi wrote:

                    What is C# language Can do and what is Cannot Do?

                    That depends more on the abilities of the programmer than the language. Marc Pensieve Some people believe what the bible says. Literally. At least [with Wikipedia] you have the chance to correct the wiki -- Jörgen Sigvardsson

                    1 Reply Last reply
                    0
                    • Steve EcholsS Steve Echols

                      The biggest limitation (compared to c++) for me is the lack of multiple inheritance. Interfaces just can't compete, because you end up duplicating tons of code that should be in a base class. At least that's my experience, which isn't much, because I gave up when my fingers started to hurt from cutting and pasting. :-D


                      - S 50 cups of coffee and you know it's on!

                      R Offline
                      R Offline
                      Rocky Moore
                      wrote on last edited by
                      #13

                      Yeah, when I first started in C# that was almost a show stopper. But after a while I realized that over the years I had only used multiple inheritance a few times, most of the time a better designed eliminated the need. Still, would be nice to have the ability in that rare case I need the functionality.. Rocky <>< Latest Post: Visual Studio 2005 Standard, whats missing? Blog: www.RockyMoore.com/TheCoder/[^]

                      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