Overriding Methods

Note: This tip will not work in VisualAge for Java 2.0 unless you apply the patches for Version 2.x. Works fine in 3.0.

Overriding methods can be error prone.  All it takes is a small misspelling of the method name, the parameter names, or omitting a parameter, and you're no longer overriding; you're defining an all-new method!

VisualAge makes overriding methods so easy it's almost painful!

But overriding is just defining methods, right?

Yes it is, but there's a trick!

So what's the trick already??????

Instead of looking at your class through the workbench's package or class view, open it in the class browser's hierachy pane.  (You do this by selecting the class, bringing up it's pop-up menu, and selecting "Open to->Hierarchy.")

Bring up the pop-up menu for the "Methods" pane, and move your mouse to "Visibility."

You'll see the following options:

vis.gif (3364 bytes)

The rest of the options are the interesting ones!

So how does this help me override methods?

Simple!  Select the visibility setting that allows the method you want to override be shown.  For example, if you were subclassing a java.awt.Panel and wanted to override addImpl(), you could select Visibility->To Named Class and pick java.awt.Container from the list.

Now all you need to do is click on addImpl(...) and the method is displayed.  Edit it to contain whatever code you want and save it.   VisualAge will ask what the save meant:

By picking the latter, you've saved the method as an override for the base method.

This is great for times when you know you have to override three or four methods but can't remember them all.  Just look at the list and pick the ones that look right!