Java Reference
In-Depth Information
Chapter 8. Object-Oriented Techniques
Introduction
Java is an object-oriented (OO) language in the tradition of Simula-67, SmallTalk, and C++ .
It borrows syntax from C++ and ideas from SmallTalk. The Java API has been designed and
built on the OO model. Design Patterns (see the topic of the same name), such as Factory
and Delegate, are used throughout; an understanding of these patterns will help you better
understand the use of the API and improve the design of your own classes.
Advice, or Mantras
There are any number of short bits of advice that I could give. A few recurring themes arise
when learning the basics of Java, and then when learning more Java.
Use the API
I can't say this often enough. A lot of the things you need to do have already been done by
the good folks who develop the standard Java library (and third-party libraries). And this
grows with every release. Learning the API well is a good grounds for avoiding that deadly
“reinventing the flat tire” syndrome—coming up with a second-rate equivalent of a first-rate
product that was available to you the whole time. In fact, part of this topic's mission is to
prevent you from reinventing what's already there. One example of this is the Collections
API in java.util , discussed in Chapter 7 . The Collections API has a high degree of gener-
ality and regularity, so there is often no need to invent your own data structuring code.
Exceptions to the rule
There is one exception to the “use the API” rule: the clone() method in java.lang.Object
should generally not be used. If you need to copy an object, just write a copy method, or a
“copy constructor.” Joshua Bloch's arguments against the clone() method in the topic Ef-
fective Java (Addison-Wesley) are persuasive, and should be read by any dedicated Java pro-
grammer. While you're at it, read that whole book.
Search WWH ::




Custom Search