Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

Multiple inheritance in .NET/ Java...

premarthapremartha Posts: 12Member
Can anybody please explain me the technical issues why multiple inheritance was discarded from Java and even from .NET. why and how it can be dangerous. I could not understand till now, even why and how pointers can be dangerous while developing internet applications and hence ruled out in Java/ .Net??

If anybody can use some examples of give me some links to resources on such issues, would be very helpful to me in understanding the things at depth, even if its not that necessary from the point of view of programing.

Comments

  • IDKIDK Posts: 1,784Member
    : Can anybody please explain me the technical issues why multiple inheritance was discarded from Java and even from .NET. why and how it can be dangerous. I could not understand till now, even why and how pointers can be dangerous while developing internet applications and hence ruled out in Java/ .Net??
    :
    : If anybody can use some examples of give me some links to resources on such issues, would be very helpful to me in understanding the things at depth, even if its not that necessary from the point of view of programing.
    :
    If you search msdn you'll find the answear of a lot...
    You could also try google

    Multiple inherence was removed becouse it was to messy...
    But if you're a good programmer you wont do it messy (wich I do all the time...)
    So it is a protection against all the bad programmer, (wich is almost all except the really good one's...)

    [grey]The one and only [b]Niklas Ulvinge[/b][/grey] [white]aka [b]IDK[/b][/white]

  • weiccoweicco Posts: 950Member
    : Can anybody please explain me the technical issues why multiple inheritance was discarded from Java and even from .NET. why and how it can be dangerous. I could not understand till now, even why and how pointers can be dangerous while developing internet applications and hence ruled out in Java/ .Net??
    :
    : If anybody can use some examples of give me some links to resources on such issues, would be very helpful to me in understanding the things at depth, even if its not that necessary from the point of view of programing.
    :

    What I've understood is that inheritance is for specializing the derived class, like the famous animal - cat example where Cat-class inherits Animal-class.

    But how can you specialize multiple classes into one class? Does your Cat-class inherit Animal-class and Mammal-class? That would be stupid and it could be fixed by inheriting Cat from Mammal, which inherits Animal. So if you'll have to inherit multiple classes you have something seriously wrong in your design.

    If you want to write some code which uses really ugly multiple-inheritance, start Symbian-project with C++ :)
  • IDKIDK Posts: 1,784Member

    : But how can you specialize multiple classes into one class? Does your Cat-class inherit Animal-class and Mammal-class? That would be stupid and it could be fixed by inheriting Cat from Mammal, which inherits Animal. So if you'll have to inherit multiple classes you have something seriously wrong in your design.
    :
    What if a cat and a dog breed? (OK, it can't happen in life, but it could happend in a computer)

    [grey]The one and only [b]Niklas Ulvinge[/b][/grey] [white]aka [b]IDK[/b][/white]

  • weiccoweicco Posts: 950Member
    :
    : : But how can you specialize multiple classes into one class? Does your Cat-class inherit Animal-class and Mammal-class? That would be stupid and it could be fixed by inheriting Cat from Mammal, which inherits Animal. So if you'll have to inherit multiple classes you have something seriously wrong in your design.
    : :
    : What if a cat and a dog breed? (OK, it can't happen in life, but it could happend in a computer)
    :
    : [grey]The one and only [b]Niklas Ulvinge[/b][/grey] [white]aka [b]IDK[/b][/white]
    :
    :

    That would end up in StackOverflowException. The minute that class is instantiated it would start chasing itself in endless loop causing serious performance problems to system. :)

    But seriously speaking... Maybe my example wasn't so good but I'll still stick to my point. Need for multiple inheritance is caused by design error in code. I'm not telling that its against law to use it but I'm strongly recommending not to use it.
  • IDKIDK Posts: 1,784Member
    : : What if a cat and a dog breed? (OK, it can't happen in life, but it could happend in a computer)
    : :
    : : [grey]The one and only [b]Niklas Ulvinge[/b][/grey] [white]aka [b]IDK[/b][/white]
    : :
    : :
    :
    : That would end up in StackOverflowException. The minute that class is instantiated it would start chasing itself in endless loop causing serious performance problems to system. :)
    :
    : But seriously speaking... Maybe my example wasn't so good but I'll still stick to my point. Need for multiple inheritance is caused by design error in code. I'm not telling that its against law to use it but I'm strongly recommending not to use it.
    :
    Why would it be stackoverflow?
    They don't call eachother, they just call the parent:
    [code]
    ____ Dog ____
    /
    mammal < > wierdthing
    ____ Cat ____/
    [/code]
    wierdthing inherits from cat and dog, and both inherit from mammal, but none of them calls eachother causing stackoverflow.

    [grey]The one and only [b]Niklas Ulvinge[/b][/grey] [white]aka [b]IDK[/b][/white]

Sign In or Register to comment.