473,378 Members | 1,412 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

Alternatives to MI in managed code???

Since managed code (C++/C#/etc.) doesn't support multiple inheritance, does
anyone have a suitable work-around? To me, this is a *serious* limitation of
the .NET subsystem.

I'm aware of *interfaces*, but they are for the *USER* of the class, not the
*IMPLEMENTOR*. I'm also aware of adding multiple classes to a class and then
creating wrappers (more of a HAS-A implementation than IS-A), but that is
tedious and again is more for the class user and doesn't support polymorphism.

Here is an example:

Suppose I have a non-trivial class that has no interface (it is purely a
functional component). There is *no way* to add an interface (ala forms) to
that component without changing the base class itself.

--
Bret Pehrson
mailto:br**@infowest.com
NOSPAM - Include this key in all e-mail correspondence <<38952rglkwdsl>>
Nov 15 '05 #1
10 1236
Bret Pehrson wrote:
Suppose I have a non-trivial class that has no interface (it is
purely a functional component). There is *no way* to add an
interface (ala forms) to that component without changing the base
class itself.


Why not inherit from System.Windows.Form?

--
There are 10 kinds of people. Those who understand binary and those who
don't.

http://code.acadx.com
(Pull the pin to reply)
Nov 15 '05 #2
> Why not inherit from System.Windows.Form?

As I said:
There is *no way* to add an
interface (ala forms) to that component without changing the base
class itself.

I don't have access to the base class to modify its inheritance.
Frank Oquendo wrote:
Bret Pehrson wrote:
Suppose I have a non-trivial class that has no interface (it is
purely a functional component). There is *no way* to add an
interface (ala forms) to that component without changing the base
class itself.


Why not inherit from System.Windows.Form?

--
There are 10 kinds of people. Those who understand binary and those who
don't.

http://code.acadx.com
(Pull the pin to reply)


--
Bret Pehrson
mailto:br**@infowest.com
NOSPAM - Include this key in all e-mail correspondence <<38952rglkwdsl>>
Nov 15 '05 #3
Bret Pehrson wrote:
I don't have access to the base class to modify its inheritance.


If you have access to the derived class, derive a new class from it and
System.Windows.Form.

--
There are 10 kinds of people. Those who understand binary and those who
don't.

http://code.acadx.com
(Pull the pin to reply)
Nov 15 '05 #4
> If you have access to the derived class, derive a new class from it and
System.Windows.Form.
And that, my friend, is multiple inheritance, which isn't a part of the .NET
subsystem. See my point?

Frank Oquendo wrote:
Bret Pehrson wrote:
I don't have access to the base class to modify its inheritance.


If you have access to the derived class, derive a new class from it and
System.Windows.Form.

--
There are 10 kinds of people. Those who understand binary and those who
don't.

http://code.acadx.com
(Pull the pin to reply)


--
Bret Pehrson
mailto:br**@infowest.com
NOSPAM - Include this key in all e-mail correspondence <<38952rglkwdsl>>
Nov 15 '05 #5
Base->inherited->inherited2->blah Inherit one after another.
"Bret Pehrson" <br**@infowest.com> wrote in message
news:40***************@infowest.com...
If you have access to the derived class, derive a new class from it and
System.Windows.Form.
And that, my friend, is multiple inheritance, which isn't a part of the

..NET subsystem. See my point?

Frank Oquendo wrote:

Bret Pehrson wrote:
I don't have access to the base class to modify its inheritance.


If you have access to the derived class, derive a new class from it and
System.Windows.Form.

--
There are 10 kinds of people. Those who understand binary and those who
don't.

http://code.acadx.com
(Pull the pin to reply)


--
Bret Pehrson
mailto:br**@infowest.com
NOSPAM - Include this key in all e-mail correspondence <<38952rglkwdsl>>

Nov 15 '05 #6
<di********@discussion.microsoft.com> wrote:
Base->inherited->inherited2->blah Inherit one after another.


That doesn't help Bret. There is no way of taking two unrelated,
unmodifiable base classes (as he has) and creating one derived class
which inherits, directly or indirectly, from both of them.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 15 '05 #7

"Bret Pehrson" <br**@infowest.com> wrote in message
news:40***************@infowest.com...
Since managed code (C++/C#/etc.) doesn't support multiple inheritance, does anyone have a suitable work-around? To me, this is a *serious* limitation of the .NET subsystem.

I'm aware of *interfaces*, but they are for the *USER* of the class, not the *IMPLEMENTOR*. I'm also aware of adding multiple classes to a class and then creating wrappers (more of a HAS-A implementation than IS-A), but that is
tedious and again is more for the class user and doesn't support polymorphism.
Here is an example:

Suppose I have a non-trivial class that has no interface (it is purely a
functional component). There is *no way* to add an interface (ala forms) to that component without changing the base class itself.


Implementation inheritance (i.e., inheriting only for the purposes of
reusing an implementation) is often questionable. You should inherit only if
there really is an 'is-a' relation between the classes, IMO.

I think the way you should go about this is to use composition. This is
admittedly more coding - you'll need to manually delegate method calls from
the containing class to the containee - but it keeps the design cleaner. In
your case, you might want to consider creating a Form class that has the
functional class as its member. The Form can then expose its own interface
and implement it in terms of the functional class.

Sami
Nov 15 '05 #8

Hi Bret,

Thank you for posting in the community!

Based on my understanding, you want to make your non-UI component to have
UI.
================================================== ==
..Net does not support multi-inheritance, so you can not inherit from other
control class to include UI function.

I agree with Sami that the simplest way to do is using composition. You
only need to create a UI object in your component.

You also may override a UI class and implement your component function in
the child class.

================================================== ==
Please apply my suggestion above and let me know if it helps resolve your
problem.

Thank you for your patience and cooperation. If you have any questions or
concerns, please feel free to post it in the group. I am standing by to be
of assistance.
Have a nice day!!

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

Nov 15 '05 #9
I've often wanted this feature for building custom asp.net server controls.
When I need to make a common modification to 23 of the standard controls
included in the vs.net toolbox (framework itself) I found myself
copy-and-pasting the same code into 23 inherited classes that represent each
control. I didn't like that because if my original code had a typo or
defect, I had to go and re-copy-and-paste all those others and it got to be
so time consuming that I actually found it much faster and easier to create
my own base class that inherits webcontrol and then all of the 23 custom
control inherit that. Then, I re-implement all of the 23 controls in
ASP.NET from scratch. My productivity is much higher now.

I could not find a way to both inherit from the original control and from my
common base class which would have only contained the addition "common"
functionality (not inherited from webcontrol) for all 23 classes. I don't
want to use the "composition" technique, either. Because that wouldn't have
solved my problem without all the code duplication and there is less
productivity, IME (in my experience).

So I'm highly productive now but have reimplemented the controls from
scratch (which many may argue is less efficient because I'm not benefitting
from other people's work). Let them argue. They aren't the ones losing
productivity over this issue. The button control is a prime example of why
I want to create it from scratch, it hardcode the type as a submit and
provides no way to override it without inserting an additional attribute of
type=button and so, to provide a way to specify what type of button it is, I
had to create it from scratch. So I couldn't inherit from the base class
anyway, and reuse it, not without having this problem.

They say that MI is evil. Maybe many in the C++ world don't understand it
and they abuse it. But I've never had problems with it. Again, with
Eiffel, it is very well implemented and hardly causes problems. So I don't
see why it would be a problem in the CLR except that "common-denominator"
programmers will likely abuse it. Well, mixed unsafe code in C# can be
abused also and that didn't stop them from putting it there as are many
other features that can be abused but are still there and aren't being
abused. In the end, the prevailing argument is that it would hurt the
performance of the JIT process. I can buy that, but it can always be
optimized.

Microsoft has many of the smartest people in the world working there, I find
it hard to believe that can't find a good solution for this problem but,
Anders, will probly never allow it and that it the true reason. When the
designer is inherently biased against a feature, there is a good chance it
won't ever be more than considered and always remain and -10 in the hole
(they use a point system for determining what features to add to the
language and always starts at -10 and works its way up or not).

Thanks,
Shawn
"Bret Pehrson" <br**@infowest.com> wrote in message
news:40***************@infowest.com...
Since managed code (C++/C#/etc.) doesn't support multiple inheritance, does anyone have a suitable work-around? To me, this is a *serious* limitation of the .NET subsystem.

I'm aware of *interfaces*, but they are for the *USER* of the class, not the *IMPLEMENTOR*. I'm also aware of adding multiple classes to a class and then creating wrappers (more of a HAS-A implementation than IS-A), but that is
tedious and again is more for the class user and doesn't support polymorphism.
Here is an example:

Suppose I have a non-trivial class that has no interface (it is purely a
functional component). There is *no way* to add an interface (ala forms) to that component without changing the base class itself.

--
Bret Pehrson
mailto:br**@infowest.com
NOSPAM - Include this key in all e-mail correspondence <<38952rglkwdsl>>

Nov 15 '05 #10

Hi Bret,

Do you still have any concern?
If you still have anything unclear, please feel free to post, we will help
you. Thanks

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

Nov 15 '05 #11

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: lolomgwtf | last post by:
I have a managed C++ method that wraps unmanaged code and creates a managed object holding data retrieved form an unmanged one. I want create an instance of this managed class in C#, pass it to...
43
by: Steven T. Hatton | last post by:
Now that I have a better grasp of the scope and capabilities of the C++ Standard Library, I understand that products such as Qt actually provide much of the same functionality through their own...
16
by: Ekim | last post by:
hello, I'm allocating a byte-Array in C# with byte byteArray = new byte; Now I want to pass this byte-Array to a managed C++-function by reference, so that I'm able to change the content of the...
2
by: asanford | last post by:
We use StackWalk(StackWalk64) from dbghelp.dll to walk our callstacksas needed, using the various Sym* methods (SymGetSymFromAddr, SymGetLineFromAddr) to resolve source file, function name, and...
4
by: William F. Kinsley | last post by:
My understanding is that when I re-compile a existing MFC application with the /clr switch, that the code generated is managed(with some exceptions) but that the data isn't, i.e. not garbage...
21
by: Strath-Clyde | last post by:
I'm a die hard c# developer, developing win32 and web based enterprise apps for last few years. The development team I'm on is going down a path I feel is wrong. I scoping out the web to knock...
5
by: Chris | last post by:
We are using SQLite.net in an application but getting a bottleneck at the data access layer (it has been profiled). This is clearly because p/invoke takes 5 to 10 times longer than it does calling...
3
by: Klaus | last post by:
Hi, I have an existing VC 6 MFC application which communicates asynchronly with a VC 2005 managed code dll. I use an unmanaged base class with virtual functions to access methods in the MFC...
3
by: =?Utf-8?B?bXVzb3NkZXY=?= | last post by:
Hi guys I've used an Application_BeginRequest function in my global.asax page to implement some URL rewriting functionality on our website. However, upon moving it to my host (1&1.co.uk), it...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.