473,385 Members | 1,353 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,385 software developers and data experts.

How to do multiple inheritances?

Hi,

I think the derived class in C# can inherit from only one class. So, if I need multiple inheritances, I will need to have interfaces. However, interfaces doesn't have the implementation of methods. Suppose, if I want to have a derived class inherit the actual methods from 3 different base classes, how can I do that?

Thanks.

Nov 15 '05 #1
3 1372
Encapsulation is the only manner you can do this with, and that gets complicated
with three
classes. What you might do here is use some reflection utilities that generate
method thunks
on your class that then map internally to copies of the three other classes you
hold instances
to. Of course the plumbing of making sure your local variables are used,
initializing those 3
different classes, etc... are all up to you.

I've done some similiar items with creating a Regex string class. Obviously
Regex and String
are both separate classes and so I had to aggregate the methods together.
--
Justin Rogers
DigiTec Web Consultants, LLC.

"ligth_wt" <an*******@discussions.microsoft.com> wrote in message
news:C8**********************************@microsof t.com...
Hi,

I think the derived class in C# can inherit from only one class. So, if I need multiple inheritances, I will need to have interfaces. However, interfaces
doesn't have the implementation of methods. Suppose, if I want to have a
derived class inherit the actual methods from 3 different base classes, how can
I do that?
Thanks.

Nov 15 '05 #2
Thanks for your hints. What you've said is a bit out out of my head. Is there a place to find a good example? Thanks.
Nov 15 '05 #3
Multiple Inheritance, like you have mentioned, isnt supported. To achive
what you wish, the more advanced mechanism to assume is that of delegation.
Out of the three classes you wish to inherit functionality, choose the best
abstraction for the root. Try using the is-a test to make sure you get the
most appropriate class. On this class, realize the two other interfaces
(roles) by implementing them on the class:

public class A : IRoleB, IRoleC
{
private IRoleB _iRoleB;
private IRoleC _iRoleC;

public A(IRoleB roleBImplementation, IRoleC roleCImplementation)
{
_iRoleB = roleBImplementation;
_iRoleC = roleCImplementation;
}

// IRoleB methods
....

// IRoleC methods
...
}

In many cases, multiple inheritance of three classes (or even two) can
typically be broken down into the design above, which is much more flexible,
and open and closed.

HTH

Nick.
"ligth_wt" <an*******@discussions.microsoft.com> wrote in message
news:C8**********************************@microsof t.com...
Hi,

I think the derived class in C# can inherit from only one class. So, if I need multiple inheritances, I will need to have interfaces. However,
interfaces doesn't have the implementation of methods. Suppose, if I want
to have a derived class inherit the actual methods from 3 different base
classes, how can I do that?
Thanks.

Nov 15 '05 #4

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

Similar topics

6
by: Rolf Wester | last post by:
Hi, I have a form with a select element with multiple="true". When using the GET method (I suppose the same happens with the POST method) I can seen that the form sends channels=CH1&channels=CH2...
66
by: Darren Dale | last post by:
Hello, def test(data): i = ? This is the line I have trouble with if i==1: return data else: return data a,b,c,d = test()
11
by: Ohaya | last post by:
Hi, I'm trying to understand a situation where ASP seems to be "blocking" of "queuing" requests. This is on a Win2K Advanced Server, with IIS5. I've seen some posts (e.g.,...
6
by: Ben Hallert | last post by:
Hi guys, I'm trying to figure out what bone headed mistake I made on something I put together. I've got a form (named 'context') that has a variable number of select-multiple inputs on it. ...
22
by: Matthew Louden | last post by:
I want to know why C# doesnt support multiple inheritance? But why we can inherit multiple interfaces instead? I know this is the rule, but I dont understand why. Can anyone give me some concrete...
9
by: Abhishek Srivastava | last post by:
Hello All, In IIS 6.0 We have a concept of worker processes and application pools. As I understand it, we can have multiple worker process per appliction pool. Each worker process is dedicated...
9
by: Graham | last post by:
I have been having some fun learning and using the new Controls and methods in .Net 2.0 which will make my life in the future easier and faster. Specifically the new databinding practises and...
4
by: Matt Kruse | last post by:
While developing an internal IE6-only webapp, a discussion started about the 'best' way to apply classes to data tables across multiple pages. The two arguments were: 1. Apply a single class to...
35
by: keerthyragavendran | last post by:
hi i'm downloading a single file using multiple threads... how can i specify a particular range of bytes alone from a single large file... for example say if i need only bytes ranging from...
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
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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: 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...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.