C# Limitation
-
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!
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
-
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
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
-
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
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;
-
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;
yet again that would be inheriting an implementation of an interface.. see my above post.. http://www.puzzleframework.com
-
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!
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? -
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?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"
-
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
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 -
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
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
-
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
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
-
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!
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/[^]