Problem understanding Inheritance
Posted
by dhruvbird
on Stack Overflow
See other posts from Stack Overflow
or by dhruvbird
Published on 2010-05-31T18:37:58Z
Indexed on
2010/05/31
18:43 UTC
Read the original article
Hit count: 169
design-patterns
|inheritance
I've been racking my brains over inheritance for a while now, but am still not completely able to get around it.
For example, the other day I was thinking about relating an Infallible Human and a Fallible Human. Let's first define the two:
- Infallible Human: A human that can never make a mistake. It's do_task() method will never throw an exception
- Fallible Human: A human that will occasionally make a mistakes. It's do_task() method may occasionally throw a ErrorProcessingRequest Exception
The question was: IS an infallible human A fallible human OR IS a fallible human AN infallible human?
The very nice answer I received was in the form of a question (I love these since it gives me rules to answer future questions I may have).
"Can you pass an infallible human where a fallible human is expected OR can you pass a fallible human where an infallible human is expected?"
It seems apparent that you can pass an infallible human where a fallible human is expected, but not the other way around. I guess that answered my question.
However, it still feels funny saying "An infallible human is a fallible human". Does anyone else feel queasy when they say it? It almost feels as if speaking out inheritance trees is like reading out statements from propositional calculus in plain English (the if/then implication connectives don't mean the same as that in spoken English). Does anyone else feel the same?
© Stack Overflow or respective owner