[Tutor] Objects, persistence & getting

Alan Gauld alan.gauld at freenet.co.uk
Mon Jan 17 08:48:28 CET 2005


> Well, one thing learning Java is good for is for thoroughly
> demystifying OOP.

<HOTBUTTON>
I'd have to disagree here because Java's version of OOP has
very little to do with real OOP. Java just uss classes as
a kind of modularisation mechanism and does not make much
use of tthe real OO features. In fact it doesn't even
support several of the things that enable real OO
programming.

And its class library, a strong feature because it is a
standard, is dreadful from an OOP p[erspective. In fact
I usually refer to Java as a Class Oriented Programming
rather than Object Oriented.

It is possible to use Java in an OOP way (read Brice Eckel's
"Thinking in Java" to see how) but the language itself
encourages a style of programming that is much more like
Pythons modules than true OOP.

> It's not some magical acronym of programming
> goodness, it's just an 'organic' way to organise code.

Certainly in Java thats true, and indeed even at the
higher level OOP is a way of organizing code - by
finding high level abstractions and building tree
structures based on common intefaces. But Java doesn't
encourage that structuring as much as Python does!
</HOTBUTTON>

> If I understand correctly, once an object is created, as long as
> references to it exist, it isn't garbage collected.

Yes.

> Does that make sense? So, foo is floating around in the namespace,
and
> bar just wants to grab a field of foo. Can it?

It shouldn't - it should be sending a message. One of
the bad things about Java is it encourages the use
of getXXX and setXXX style methods which are a total
anathema to real OOP. They break the Law of Demeter.

Alan G.



More information about the Tutor mailing list