|
For example I have two type of class the are derived from System.web.ui.page
TemplatedPage which suports my templating system
and
VirtualPage which suports a virtual page redirection system
(you try to get url rewriting working properly with link buttons)
now if i want to create a new Templated Virtual page I can only inherit from one or the other. As a result i have to reimplement one or the other and keep track of changes in two differant classes.
|
|
|
|
|
Interesting how no one posted this :
(pseudo language)
class Foo
{
void Fly ()
{
Output ("Foo flying");
}
}
class Bar
{
void Fly()
{
Output ("Bar flying");
}
}
class MotherLoad : Foo , Bar
{
}
MotherLoad ml;
ml.Fly();
This example is the reason why C# and Java doesn't support MI.
-
Drew
|
|
|
|
|
Solution in real lungauge (C++):
class Foo
{
public:
void Fly ()
{
Output ("Foo flying");
}
};
class Bar
{
public:
void Fly()
{
Output ("Bar flying");
}
};
class MotherLoad : public Foo, public Bar
{
};
MotherLoad ml;
Foo(ml).Fly();
Bar(ml).Fly();
<center> </center>
|
|
|
|
|
Having to cast the object to predict the output defeats one of the purposes of inheritance in my opinion. Besides you didn't anwser my question. Checking a recent ISO compliant C++ compiler reveals to me that it won't let you invoke the method because it (My version in C++) recognizes that it is ambiguous.
-
Drew
|
|
|
|
|
I was just demonstrating a simple solution to your "problem" that supposedly prevented MI support in C#. Of course MI works best if you inherit from orthogonal classes (e.g. policy based design) in which case it's unlikely to get into the trouble you're describing. And if you do then you can just resolve ambiguity either by casting or changing the names so they don't clash or whatever.
All in all it's not a big problem.
<center> </center>
|
|
|
|
|
You are correct, it does solve the problem. I suppose C# may have more lofty reasons for not supporting MI. Like with anything in life, the anwser is always 'it depends'.
-
Drew
|
|
|
|
|
Suppose I'm having a drink with my friends Joe Smith and Joe Brown and I say "Hey, Joe!". Whom am i addressing? Is it a bad thing to have friends with duplicate names? Should having duplicate-name friends be banned?
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
Want a Boost forum in Code Project? Vote here[^]!
|
|
|
|
|
Hows about the language trust the programmer to be smart enough not to do that?
|
|
|
|
|
... but I also think I tended to over use it in C++, as I think a lot of people over use many such features. I am getting used to the .Net interface style of MI, and I have to say that it does impose a kind of discipline on the practice that I am beginning to consider might just be a good thing.
Still, if true OO MI were added to C#, I would be happy.
"The Yahoos refused to be tamed."
|
|
|
|
|
|
KISS, anyone?
Salil Khedkar [^]
|
|
|
|
|
The question I have for you is this: keep what simple? Keep your design simple @ the cost of a clumsy and/or complex interface, or keep your class interface simple at the cost of a complex design (perhaps employing MI)? Like I state in my post below, I prefer the latter.
~Nitron.
ññòòïðïðB A start
|
|
|
|
|
MI is KISS. Not having MI can make the design more complicated, not less.
--
Meski
|
|
|
|
|
/me plants a big wet kiss on Salil Khedkar's face.
Die Freiheit spielt auf allen Geigen
|
|
|
|
|
for me, Multiple inheritence allows the user to use code written in the base classes which is absolutely not the case with Interfaces (VB, C#, java, ...).
the only thing interfaces allow you is to provide/write yourself the code to be used...
really different !!
another thing, MI can be very hard to use correctly, but like many features of C++ (as C++ provides MI), you also can use it usefuln and well !!
TOXCCT >>> GEII power [toxcct][VisualCalc]
|
|
|
|
|
It's a good thing.
It's already there, it works, and you can avoid it if you don't like it. How can that possibly be a bad thing? That's right - it can't. You might as well hand me a delicious lemon pie and then ask me whether being given a delicious lemon pie is a Good Thing or not... while already half the pie has been devoured! Sure, you might be tricked into thinking that for others who have been less blessed in the delicious lemon pie dept. a free delicious lemon pie might seem like a bad thing. You might even mistakenly conclude that, for those poor souls who are allergic to lemons, a free delicious lemon pie would be worse than useless... but you would be wrong. Both arguments are nothing but sour grapes - if the sad sinners in question were not so cursed with a dearth of pies or the inability to consume them, they would without question see the free pie in question as a Good Thing.
And so it is with multiple inheritance. Who says it's a Bad Thing? Those who lack it (C# and Java coders), and those who can't use it (C++ coders struggling with the basic concepts of inheritance, who probably are also bed-wetters). Face the facts: if MS had put MI in C#, the only people complaining would have Java in big bold letters on their resume.
It's a good thing. That is all.
Shog9
I'm not the Jack of Diamonds... I'm not the six of spades.
I don't know what you thought; I'm not your astronaut...
|
|
|
|
|
Couldnt have put it better myself.
|
|
|
|
|
Nice one Shog, I am in full agreement, what more can be said....
|
|
|
|
|
No its bad.
Its bad in situations where you do not have full control over the inheritance tree.
Its all well and good where C++ mimics interfaces by multiple inheritance with no data . Ok , you can work around it , but why should you have to ? Using multiple inheritance of interfaces gets around the need in a much easier to police way .
I have programmed C++ for 15 years and I do not wet the bed .
|
|
|
|
|
Andrew Torrance wrote:
Using multiple inheritance of interfaces gets around the need in a much easier to police way .
Uh, i'm not talking about work-arounds. Or police. If you need police to enforce your work-arounds, something tells me you picked the wrong language.
No offense - i have no problems with a single inheritance, multiple interface design. But that should be my choice, not the language designers.
And come on - it's much, much more convenient to mimic interfaces with pure virtual baseclasses than it is to mimic multiple inheritance with interfaces.
Shog9
I'm not the Jack of Diamonds... I'm not the six of spades.
I don't know what you thought; I'm not your astronaut...
|
|
|
|
|
Shog9 wrote:
it's much, much more convenient to mimic interfaces with pure virtual baseclasses than it is to mimic multiple inheritance with interfaces.
That's very true.
"The Yahoos refused to be tamed."
|
|
|
|
|
Shog9 wrote:
a delicious lemon pie is a Good Thing
It's delicious, so it's a good thing.
It makes you fat, so it's a bad thing.
It's a matter of opinion. It goes more with your definition of a "good thing".
A pie is delicious and when eaten in large portions will satisfy your hunger. Multiple Inheritance looks cool and makes it more convenient to code certain scenarios. But is it a "good thing"? It's a matter of opinion.
So what's mine? I like it!
Regards,
Alvaro
Victory means exit strategy, and it's important for the President to explain to us what the exit strategy is. -- GWB, 1999.
|
|
|
|
|
I think likewise.
MI is a nice to have, but comes with too many limitations and caveats (a fattening, teeth destroying, cancer causing, allergenic lemon cake).
As for template metaprogramming mentined in one post, I think its just one more ugly workaround for missing features in C++. I'd rather have no MI and a clean implementations for generic and compile time programming, than an crippled addon sublanguage using MI .
Wolfgang Reichl
|
|
|
|
|
Well said, I couldn't agree more. Its about choice after all. No one forces programmers to use multiple inheritance, and it's not the fault of the language if programmers don't know how to use it properly.
I doubt that we would even bother to pose this question if C# supported multiple inheritance.
Regards,
David
|
|
|
|
|
Supporting any feature is always a good thing when it comes to programming languages.
<center> </center>
|
|
|
|