473,513 Members | 2,552 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Half a step away from Multiple Inheritance (a suggestion)

Let's say you have three classes, ClassA, ClassB and ClassC. You'd
like ClassC to descend from ClassA and ClassB (because, for instance,
ClassA is a UserControl and Class C is all of your validation code).
At the moment you can't do it - your code either has to be in a static
helper class or copied into each class manually.

What if, as a way of checking that your code fulfilled an interface,
rather than checking that all the required methods were in place, it
could optionally see if your class could be cast to an implementation
of that interface. Like so:

class ClassC : ClassA , IClassB
{
private ClassB classB = new ClassB();
public static implicit operator IClassB(ClassC classC)
{
return classC.classB;
}
}

(where ClassB implements IClassB).

So that when calls to ClassA methods were needed they'd be passed
straight back up to it. And when calls to ClassB methods were needed it
would do a cast to ClassB and call them that way.

Have I just reinvented something really obvious? Or is there a mistake
in my thinking? Or something else?

Cheers,

Andy

Sep 13 '06 #1
1 1014
"Andrew Ducker" <an****@ducker.org.uka écrit dans le message de news:
11**********************@p79g2000cwp.googlegroups. com...

| Have I just reinvented something really obvious? Or is there a mistake
| in my thinking? Or something else?

This kind of thing has been a part of Delphi for a long time.

type
TThing = class(TInterfacedObject, IOther)
private
fOther: IOther;
property Other: IOther read fOther implements IOther;
...
end;

Very useful and sorely missed in C#.

Joanna

--
Joanna Carter [TeamB]
Consultant Software Engineer
Sep 13 '06 #2

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

Similar topics

14
6378
by: Axel Straschil | last post by:
Hello! Im working with new (object) classes and normaly call init of ther motherclass with callin super(...), workes fine. No, I've got a case with multiple inherance and want to ask if this is the right and common case to call init: class Mother(object): def __init__(self, param_mother): print 'Mother'
13
3255
by: John Perks and Sarah Mount | last post by:
Trying to create the "lopsided diamond" inheritance below: >>> class B(object):pass >>> class D1(B):pass >>> class D2(D1):pass >>> class D(D1, D2):pass Traceback (most recent call last): File "<stdin>", line 1, in ? TypeError: Error when calling the metaclass bases Cannot create a consistent method resolution
2
4321
by: Graham Banks | last post by:
Does using multiple inheritance introduce any more performance overhead than single inheritance?
5
2167
by: Morgan Cheng | last post by:
It seems no pattern defined by GoF takes advantage of multiple inheritance. I am wondering if there is a situation where multiple inheritance is a necessary solution. When coding in C++, should multiple inheritance still be avoided? If yes, why multiple inheritance is introducted into C++?
5
13146
by: IvD² | last post by:
During a project I ran into trouble when using multiple inheritance. I was able to resolve the problem, but was unable to really understand the reasons for the error. Here is a short example of the problem: class BaseA { ...
22
23320
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 examples?
3
2554
by: Hazz | last post by:
I am just beginning to design a Treeview display (winforms) for wine regions. Problem. Some wine growing regions belong to two counties. Eg. Carneros is in both Napa and Sonoma Counties. Although most nodes will have only one parent, a few will have two parents. The Treeview which seems to me to lend itself to the Windows Explorer type of app...
60
4867
by: Shawnk | last post by:
Some Sr. colleges and I have had an on going discussion relative to when and if C# will ever support 'true' multiple inheritance. Relevant to this, I wanted to query the C# community (the 'target' programming community herein) to get some community input and verify (or not) the following two statements. Few programmers (3 to7%)...
3
2626
by: ernesto | last post by:
Hi everybody I have the following class declarations: class Interface { public: virtual char* getName() const = 0; }; class BaseClass : public Interface {
10
4365
by: Aaron Gray | last post by:
Wikipedia says Python has Multiple Inheritance, is this true ? http://en.wikipedia.org/wiki/Multiple_inheritance Thanks, Aaron
0
7270
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7397
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
7543
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
4759
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3255
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3242
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1612
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
817
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
473
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.