Object-Oriented Techniques

by Jeff Hunter, Sr. Database Administrator

Introduction

The Java API was designed and built on the OO model. Having a good understanding of Design Patterns such as Factory, Bridge and Delegate, though not required to be a Java programmer, will help you to better understand the use of the API and provide better ways to construct objects more flexibly. Design Patterns are certainly one of the most successful software engineering concepts of the past few years. They act as tried and true, transferable solutions for specific problem situations and help developers to reach a finished application faster.

Use the Java APIs

What is sometimes hard to teach new comers is that much of the work you need to do has already been done within the APIs. Learning the APIs well is one great method to avoiding that "reinventing the wheel" syndrome. In most cases, not only is the code already available, but more efficient than the reinvented one. A great example is the Collections API in java.util. Given the high degree of generality and regularity, there is very little reason to invent your own data structuring code.

Use Javadoc

When learning the Java API, one of the greatest resources is the Java 2 online documentation through a web browser. For the location of all online Java API Documentation, visit http://java.sun.com/api/index.html Now the question is, where did all of this documentation come from? Did Sun hire someone to manual create the HTML for these docs? The answer is no. The documentation exists because the developers of the API took the time to write Javadoc comments when writing the code.

For a full review of writing Javadoc, visit the section labeled Javadoc within this Java Programming corner.

Simply put, use Javadoc. Java provides one of the best mechanisms for API documentation. Also, always document as you write the code. How often do you come back to the code at a later time to document.

Use Design Patterns

As mentioned earlier in this document, I discussed the use of Design Patterns. Many books on object-oriented programming promote the use of Design Patterns as they provide a powerful catalog of code that programmers so often reinvent.