G
Guest
Hi ,
Can Anyone explain me exactly why multiple inheritance not used in java and c#
thanks,
Mahesh
Can Anyone explain me exactly why multiple inheritance not used in java and c#
thanks,
Mahesh
MAHESH MANDHARE said:Can Anyone explain me exactly why multiple inheritance not used in java and c#
Mark Broadbent said:http://blogs.msdn.com/csharpfaq/archive/2004/03/07/85562.aspx
My personal opinion (for what it is worth!) is that it is a real shame not
to include this (regardless of all the potential pitfalls). Having heard a
speech by Anders a couple of years back, I got the impression that he
really didn't like it. But I guess that there has been only a few
occasions that I thought that I really wanted to be able to do this ...but
maybe my approach is different because I know I can't.
Br,
Mark.
MAHESH MANDHARE said:Complexity can not be the reason for not adding MI
MI can depict Real world model when class derives from two or more
parents,we can use interfaces for that I aggree but Language Lacks
one of the object oriented paradigm
Radek Cerny said:I agree wholeheartedly. I had MI in a previous world (Gupta/Centura 4GL)
and I miss it dearly. Mind you I think that all in all, c# is pretty damn
good, but I can make several real cases where MI is the correct design/model
and would save a fair amount of duplication. I have pretty much given up
hope on ever seeing it in the CLR tho.
Radek
Radek said:I agree wholeheartedly. I had MI in a previous world (Gupta/Centura 4GL)
and I miss it dearly. Mind you I think that all in all, c# is pretty damn
good, but I can make several real cases where MI is the correct design/model
and would save a fair amount of duplication. I have pretty much given up
hope on ever seeing it in the CLR tho.
Radek
Wiebe Tijsma said:Sounds like you're tightly coupling components directly to your model,
maybe you just need to apply the MVC (Model-View Controller) pattern.
You can mimic MI by delegating your interface to a class implementing the
same interface right?
It does require you to redeclare all implementing methods indeed, wich is
a pain if your interface is fairly complex and need to implement it on
many classes.
Antoher option is to declare 2 interfaces/base class, and have your
classes work with both. like the IXPathNavigable and XPathNavigator, where
the declaring interface only consists of 1 method that retrieves the more
complex base class instance:
interface IXPathNavigable {
XPathNavigator CreateNavigator();
}
like this:
interface IMyInterface {
... many methods implementation ...
}
interface IMyInterfaceSource {
IMyInterface GetMyInterface()
}
public class MyClass : IMyInterface, IMyInterfaceSource {
/* many methods implementation */
IMyInterface IMyInterfaceSource.GetMyInterface(){
return this;
}
}
// Your inherited components only need to implement IMyInterfaceSource, //
wich could be relatively easy with 4 lines of code:
public class MyCheckBox : CheckBox, IMyInterfaceSource {
private IMyInterface implementation = new MyClass();
IMyInterface IMyInterfaceSource.GetMyInterface(){
return implementation;
}
}
[ I do believe interfaces should be kept simple though, and if it requires
a lot of methods, don't use interfaces but abstract base classes ]
sometimes I miss some delphi functionality, where you can delegate the
entire interface to a property of the instance. Explanation:
http://www.netindustry.nl/blog/2005/04/wheres-in-c.html
Hmm maybe I should write an article about it, any suggestions? ;-)
About the table normalization, isn't a table layout much more limited than
MI? I don't even use databases at the moment that use table inheritance at
all, let alone multiple table inheritance, wich one do you use?
Wiebe
Radek said:In my architecture, I keep 100% separation of business functionality from
presentation layer (Web Services connect a rich,thin client to functional
server objects). So I have two separate cases. Server-side, I have more
control over, as I do not use Datasets or such - my objects are built
from the ground up.
However, on the client, I must provide all controls that are capable of
talking my specific Web Service schema to the server, but I must inherit
from the standard WinForms controls. I have no choice but to replicate
code in a checkbox, textbox, radio button class etc. If I had MI, I
would have an abstract class that understood my schema, and all the
window classes would inherit from that as well as the .NET supplied
standard Windows classes. For now, I can only implement an interface,
but there is much code that is identical across controls.
Server-side, I would still like MI, but learned to live without it.
Philosophically, I can not understand those who do not appreciate MI;
used correctly, you can normalise your code base like you would normalise
your database.
Radek
cody said:There is a proposal from Anders Hejlsberg to add support for a default
implementation to interfaces to C#, this is something like a limited support
for MI but sounds useful.
Tom said:MI is a feature of OO.
Without MI, you couldn?t represent real world objects
as they are in the real world? When you?re doing your design, you model
things as they are in the real world, and therefore creating an accurate
representation of the things within your system.
However, because not all
the features of OO are supported within the language (C#, Java?) you need to
make implementation decision within your design? If the thing in the system
is derived from several other things, then surely the language should support
that? Good design will mean that MI only happens where it actually happens
in the real world.
And anyway, shouldn?t it be up to the designer at design time how
complicated a part of a system is, why should the language inhibit the
ability to create systems which represent the design? Bad design brings many
problems, coupling cohesion and MI problems? Good design prevails, let
people have MI.
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.