Re: Inheritance versus Composition
printdude1968@gmail.com wrote:
On Mar 14, 11:12 pm, Eric Sosman <esos...@acm-dot-org.invalid> wrote:
printdude1...@gmail.com wrote:
I am reading the book Learning Java (O'Reilly) and there is a section
which says to favor composition over inheritance. Having no
experience with composition, I am wondering what the general concensus
of the group is. Which is better, inheritance or composition. [...]
Which is better, mitosis or meiosis?
Which is better, ski-jumping or prestidigitation?
Which is better, black or sour?
Which is better, waltz or octopus?
(In other words, you have asked a question that makes no
sense. You do not understand the words you are using; this is
a natural state of affairs for a beginner, but the cure is to
gain an understanding of the terms, not to engage in a debate
over the relative merits of phrenology and eschatology.)
I am not attempting to engage in a debate, I am only asking for
opinions. It seems to me that the other responders to my question
were
able to give me good things to ponder. As it turns out, the question
I ask is posed due to something I read in a book called Learning Java
(as I stated in my original post) so it seems to me that it is quite
valid for me to ask questions about something I read in the very early
stages of a book.
I suspect I may have offended you, which was not my intent.
If I have done so, I ask your forgiveness.
The reason I think your question makes no sense is that it
asks "which is better" but doesn't say anything about "for what
purpose?" Mitosis is not "better than" meiosis; they are
different (although related) processes with different functions.
If you want to make red blood cells mitosis is better than
meiosis; if you want to make eggs it's the other way around.
Similarly with inheritance and composition: They are related
(both are ways of deriving a more specialized construct from a
more general substrate), but they are different and serve different
purposes. Neither is "better" than the other in isolation, not
until the purpose enters the picture.
Which is better, a bicycle or a banana? It depends on whether
your purpose is to get from Here to There, or from Hungry to Fed.
--
Eric Sosman
esosman@acm-dot-org.invalid