Re: Java and OOP



On Jan 17, 2:37 am, Arne Vajhøj <a...@xxxxxxxxxx> wrote:
soup_or_po...@xxxxxxxxx wrote:
....
Also, can anyone comment on delegation which is an alternative to OOP?

Delegation is not an alternative to OOP. It works fine with OOP.

Can multiple inheritance be done with delegation?

No. And Java does not support multiple inheritance.

Java supports multiple interface inheritance. Some OO languages
have no concept of implementation inheritance and support
multiple inheritance, so I think your statement needs
clarification.

"Java supports multiple interface inheritance, but does
not support multiple implementation-inheritance... And
implementation-inheritance has nothing to do with OO".

I *think* what the OP refers too is that the most
common (broken) complain about Java regarding inheritance
is that people cannot "reuse code" [sic] from several classes.

What these people want to do can easily be achieved by
using multiple interface inheritance and delegating the
calls to wrapped objects.

So delegation is not an alternative to OOP, but it can
be used to easily circumvent the "problems" of not having
multiple implementation-inheritance.

I *think* this is what the OP's question is about.

300K LOC project here with zero instance of the keywords
"abstract" and "protected" and where every single class
is final. It can be done, and it's actually done (and
sometimes enforced by guidelines and build scripts) in
several projects.

Once again it should be noted that James Gosling himself
expressed regret not having gone "pure interface", leaving
that ugly implementation-inheritance wart on the side
(that is an opinion of course, which just happens to match
the opinion of Java's creator ;)

Direct link to the paragraph where James Gosling explains
how delegation can be used to fix implementation-inheritance
problems [sic]:

http://www.artima.com/intv/gosling34.html

B.V.:: Bill Venners: But by delegation, you do mean this
B.V.:: object delegating to that object without it being a subclass?

J.G.: James Gosling: Yes -- without an (concrete) inheritance
J.G.: hierarchy. Rather than subclassing, just use pure interfaces.
J.G.: It's not so much that class inheritance is particularly bad.
J.G.: It just has problems.

Java would actually have been more elegant without implementation
inheritance: no more "abstract" keywords, no more final/non-final
class distinction (they would all have been final).

Once again it's just an opinion.

But Java does support multiple inheritance and OO analysis/design
requiring multiple inheritance can be programmed in Java in a
very simple (and in my opinion very clean) way,

Driss


.



Relevant Pages

  • Re: Multiple Inheritance
    ... "Java has multiple inheritance. ... James Gosling writes: ...
    (comp.lang.java.programmer)
  • Re: Why multiple inheritance is not allowed in Java
    ... instead of C++ style of multiple inheritance??. ... and Interface not why Interface concept required in Java. ... Interface concept in Java. ... The Eiffel people came up with a fairly clean solution to the multiple ...
    (comp.lang.java.help)
  • Re: On assembly and portability (between Linux and Windows)
    ... Java does not support multiple ... > The point is that it supports simple inheritance for classes and multiple ... doesn't support Multiple inheritance, and thus isn't an object oriented ... I said OOP doesn't require multiple inheritance, and used Java ...
    (alt.lang.asm)
  • Re: lines of code?
    ... > a) I should have qualified my statement about multiple ... > context of java gui; I'm no java expert, ... multithreading being "required" in Java is relevant, ... to unnecessarily implementing something as a state machine. ...
    (comp.programming)
  • Re: lines of code?
    ... > a) I should have qualified my statement about multiple ... > context of java gui; I'm no java expert, ... multithreading being "required" in Java is relevant, ... to unnecessarily implementing something as a state machine. ...
    (comp.lang.java.programmer)