Question

I was discussing multiple inheritance vs. single inheritance with a friend of mine, and discovered that plainly, my conception of Object-Oriented design is completely different than his. I am mostly an Obj-C programmer, so Multiple Inheritance is not something I use daily. He is mostly a C++ programmer under Windows/PSP, so we probably use different concepts on a day-to-day basis.

He actually brought the following subject : What does a new human being inherit from?

My conception of that was that there would be a Human class, and the new being would inherit from that class and get some instance variables (such as his DNA and others) from his two parents.

His conception was that the child would inherit from his two parents, in order to get the methods of his parents.

And now I'm kind of confused, because honestly... Inheriting from objects? Isn't inheritance used to inherit from classes which contain methods common to a certain group of objects? This argument really confused me to no end.

Was it helpful?

Solution

The parents are also humans, which are part of the family of creatures called mammals. Your thoughts seem most logical to me.

public class Human extends Mammal implements HunterGatherer, Speech, CognitiveThought {

    public Human(Human mother, Human father) {
        super(mother, father);
        // ...
    }

    // ...
}

Certainly I can't see:

public class Human extends Mother, Father { ... }

I see the mother and father as being rather involved in the construction of their child, all three are humans.

OTHER TIPS

To take the analogy head-on, the new human gets its traits from a pair of zygotes generated by the parents, which are only loosely based on the parents' own DNA.

Realistically, I think this is just a bad analogy. Just because "inheritance" is a borrowed term from genetics (or wills and contract law?) doesn't mean it has to conceptually match 1:1 with software development, and in fact they are only superficially similar concepts.

For example, my father is a lawyer, and my mother is a school teacher. I was not born with the skills (behaviours, methods...) of either one.

You're both wrong... Both Child and parents are instances of Human Being... . As example, in one possible class structure, HumanBeing (ALL of them) all inherit from "Primate" which Inherits from "Mammal" which Inherits from "Animal"...

Human Being Inherits all behavior of Primate, Like "WalkUpright()", etc.
Primate Inherits all behavior from Mammals, like "Lactate()" "LiveBirth(), etc... Mammal Inherits behavior from Animal...

Each Instance of HumanBeing could have two properties called Father, and Mother, that are each an instance of HumanBeing...

and perhaps another property called Children, that contains a collection of instances of HumanBeing objects...

Agree with JeeBee, the parents have a construction role!

public Class HumanFactory(Human mother, Human father)
{
    public Human NewHuman()
    {
        while(!mother.IsPregnant)  // may loop infinitely in the infertile case
            father.Mate(mother)
        while(mother.IsPregnant)
            System.Threading.Sleep(1000); // may take some months, get comfortable
        return mother.DeliverBaby();
    }
}

A human would be a class, and all humans beings belong to the same class.

The child, the father and the mother are only instances of that class.

The mother and father are just factories ( the the human itself composite )

We may inherit from the "missing link" though, it depends of the domain.

But your friend has a point, Achilles for instance inherit from a Nymph and a Human :S hence multiple inheritance proved.

Superman inherit Kriptonian while Spiderman is a human that implements Spider! :P

Well I think the parents are also human. So parents is a property of Human. It has nothing to do with OOP inheritance. It may do so if you are referring to types of human as represented by race such as Caucasian extends Human

In terms of object oriented behaviour your friend's conception is wrong. A person does not inherit behaviours from their parents in the same way that a class does. A person inherits genes - half from each parent - and these genes combine to cause behaviours. For example even if both parents have a particular eye colour, the child doesn't necessarily have the same eye colour (look up recessive genes if you didn't take high school biology).

In short, don't think about human inheritance when you are thinking about class inheritance. It almost certainly won't be helpful.

The short answer is that both your and your friend's conception of inheritance have been held by many people and are equally legitimate.

Your friend's conception is closer to "object inheritance" in "prototype based" OO languages (eg. Self and Javascript). Yours is more in line with "class inheritance" which is typical of Smalltalk, Java and, yes, C++.

Java (particularly recently) has tended to see inheritance as all about managing types and now urges "composition" instead of inheritance for code-reuse, This is partly because inheritance is less flexible in Java than composition so "prefering composition" is good practice. And partly because of the "brittle base-class problem".

But if your friend is more used to creating "mixins" he may well see inheritance more as a kind of library include. That may not be the best practice in either Java or C++, but it is a way that inheritance has often been understood.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top