Presents your JAVA E-NEWSLETTER for July 25, 2002 <-------------------------------------------> ENFORCE A PIECE OF API IMPLEMENTATION If you want to set up a pluggable interface and ensure a piece of functionality, use an abstract class with two different methods. Application program interface (API) developers often want to make sure that a small part of functionality always occurs. An example of this is a translation system in which the developer is assured that the translated word will be in lowercase. To do this, provide a public method that will be called and a protected method, which will be overridden. Here's an example: abstract public class Translator { public final String translate(String word) { word = word.toLowerCase( ); return translateWord(word); } abstract protected String translateWord(String word); } To translate to Pig Latin, a developer extends the abstract class. For example: public class PigLatinTranslator extends Translator { protected String translateWord(String word) { return word.substring(1) + word.substring(0,1) + "ay"; } } Here's an example of the user code: .... PigLatinTranslator translator = new PigLatinTranslator( ); translator.translate("seal"); // return ealsay .... The user of the translator has to employ the public translate method, while the extender is forced to use the protected translateWord method. This will make sure that the code runs. CORRECTION: In a recent Java tip ("Manage a series of options with the BitSet class," July 8, 2002), we told you how BitSets can be merged together via the Boolean algebra methods and, xor, and andNot. We provided an incorrect example. 10001 and 00001 will return 00001, not 10000. We apologize for any inconvenience this may have caused. ----------------------------------------