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 the latter and ideas from SmallTalk. The Java API has been designed and built on the OO model. The Design Patterns (see the book of the same name) such as Factory and Delegate are used throughout; an understanding of these, though not required, will help you to better understand the use of the API.

Advice, or Mantras

There are any number of short bits of advice that I could give, and a few recurring themes that arise when learning the basics of Java, and then learning more Java.

Use the API

Can’t say this often enough. A lot of the things you need to do have already been done by the good folks at JavaSoft. 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. This is, in fact, part of this book’s mission -- to prevent you from reinventing what’s already there. One example of this is the Collections API in java.util, discussed in the previous chapter. It has a high degree of generality and regularity, so there is usually very little reason to invent your own data structuring code.

Generalize

There is a trade-off between generality (and the resulting reusability), which is emphasized here, and the convenience of application specificity. If you’re writing one small part ...

Get Java Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.