Yesterday, One of my friends, Dharmendra ask me why C# does not support multiple inheritance. This is the question most of the people ask every time. So I thought it will be good to write a blog post about it. So why it does not support multiple inheritance?
I tried to dig into the problem and I have found the some of good links from C# team from Microsoft for why it’s not supported in it. Following is a link for it.
http://blogs.msdn.com/b/csharpfaq/archive/2004/03/07/85562.aspx
Also, I was giving some of the example to my friend Dharmendra where multiple inheritance can be a problem.The problem is called the diamond problem. Let me explain a bit. If you have class that is inherited from the more then one classes and If two classes have same signature function then for child class object, It is impossible to call specific parent class method.
Here is the link that explains more about diamond problem.
http://en.wikipedia.org/wiki/Diamond_problem
Now of some of people could ask me then why its supporting same implementation with the interfaces. But for interface you can call that method explicitly that this is the method for the first interface and this the method for second interface. This is not possible with multiple inheritance. Following is a example how we can implement the multiple interface to a class and call the explicit method for particular interface.
Multiple Inheritance in C#
That’s it. Hope you like it. Stay tuned for more update..Till then happy programming.
I tried to dig into the problem and I have found the some of good links from C# team from Microsoft for why it’s not supported in it. Following is a link for it.
http://blogs.msdn.com/b/csharpfaq/archive/2004/03/07/85562.aspx
Also, I was giving some of the example to my friend Dharmendra where multiple inheritance can be a problem.The problem is called the diamond problem. Let me explain a bit. If you have class that is inherited from the more then one classes and If two classes have same signature function then for child class object, It is impossible to call specific parent class method.
Here is the link that explains more about diamond problem.
http://en.wikipedia.org/wiki/Diamond_problem
Now of some of people could ask me then why its supporting same implementation with the interfaces. But for interface you can call that method explicitly that this is the method for the first interface and this the method for second interface. This is not possible with multiple inheritance. Following is a example how we can implement the multiple interface to a class and call the explicit method for particular interface.
Multiple Inheritance in C#
That’s it. Hope you like it. Stay tuned for more update..Till then happy programming.
Мне понравилось! Также отличные статьи написаны здесь - vkone.ru/ movir.ia.ua/
ReplyDeleteI liked it! Also excellent articles written here - vkone.ru/ movir.ia.ua/
ReplyDeleteWhen someone asks about multiple inheritance, you'd better ask: "Why do you need it? Can you give an example of a problem that cannot be solved without it?" I think it's likely you won't get a convincing response. Especially because object oriented programming taught us to favor object composition over inheritance.
ReplyDeleteCristi Lupaşcu - Yes correct and we can do all things with interlace
ReplyDeleteIlya Malinskyy - Thanks but its in Russian and I don't know that.
ReplyDelete