Implementing Interfaces


Version 3.0 of VisualAge now has an option "Generate->Required Methods" from the popup menu of a class. This creates stubs for each method listed in any interfaces you add to the implements clause of your class definition.

Use this option if you add a new interface after you have already created a class.

Submitted by: Chris Burkey

If you have to implement an interface what you should is let VA do all the work!.


Just use the wizard to create a new class.  make it a subclass of whatever you want.  Make sure you select "write source code for the class" and press "Next".

On the next screen, you'll see

interface.gif (1427 bytes)

This means that if there are any abstract methods in the class you are extending, or if you specify an Interface to implement (on the next screen) it will create skeleton code for those methods!

Make sure you press Next to get the next screen!

At the top of the SmartGuide there is a box where you can enter the interfaces that you want to implement.  Press the "add" button next to the box to add the interface.

When you finish, VisualAge will create the class, making it implement the interface(s) you selected.  It will also add all the methods listed in those interfaces, and any abstract methods from superclasses of your class.

All you have to do is fill in the blanks...

But what if I already have a class???

Make sure you check out Tim deBoer's tools for VisualAge for Java.  He has a tool that adds the methods of an interface to your class!

Surf to the tools page to see it!