For a class to implement an interface, it must:
Indicate that it wants to use a specific interface
Satisfy the interface requirements by implementing all of the interfaces methods
For a class to implement an interface, it enters into a contract to provide a mapping between each method in the interface and a method from the class. This does not have to be a one-to-one relationship, as one class method can map to multiple interface methods for a specific interface or to one or more methods in multiple interfaces.
The only requirement is that the method signatures are compatible.
To implement an interface
In the Class List of the Class Browser, select the class that is to use the interface.
Select the Interface Mapping command from the Classes menu.
The Interface Implementation Mapper dialog is then displayed.
In the Available Interfaces list box, select the interface that you want to implement. Alternatively, if you want to search for an interface, press F4.
The Find Type dialog is then displayed, listing all available interfaces for classes in the schema from which you invoked the Interface Implementation Mapper dialog.
When you select an interface in the Available Interfaces list box of the Interface Implementation Mapper dialog (or in the Find text box of the Find Type dialog and you then click the OK button), the methods defined in the selected interface that the class must implement to satisfy the interface are then displayed in the first column of the table beneath the Available Interfaces list box.
An interface cannot be implemented by a class if it is already implemented by that class in a superschema or a subschema.
The JADE mapping to that interface (that is, the stub method that is automatically generated in a class when you define an interface method) is displayed in the second column.
In addition, a summary of all methods and constants defined in the selected interface are displayed in the read-only pane in the middle of the dialog, as shown in the following image.
If you want to list all interfaces for the current schema and its superschemas in the Available Interfaces list box, check the Show All check box. By default, only interfaces of the current schema view are listed (for example, if the owning Class Browser is viewing the current schema and superschema classes, by default interfaces in both those schemas are listed).
You can enter any valid method name in the combo box of a cell in the second column, to create a new class method (to which normal method naming rules apply) or you can select an existing class method (by using the drop-down list box portion of the combo box) from the list of any existing class method that has a complementary method signature.
If you want add a method prefix to all mapped method names, perform the following actions.
Ensure that the Add Method Prefix value is displayed in the Modifier list box (the default value).
Specify the value in the Value text box (for example, test_) that you want to apply to all JADE methods that are mapped to the interface.
Click the Modify button.
To remove a method prefix from all mapped methods, perform the following actions.
Select the Remove Method Prefix value in the Modifier list box.
Specify the value in the Value text box that you want to remove from all JADE methods that are mapped to the interface.
Click the Modify button.
If you want to remove a method prefix from all JADE methods in the target class that are mapped to the interface, perform the actions in this step before you click the Implement button.
As the modification of a mapped method name (both adding and removing a prefix) creates a corresponding method, removing a prefix does not remove the method from the target class. For more details, see "Stopping the Implementation of an Interface", later in this chapter.
Click the Implement button.
A method is then created for each new mapping value that you specified or selected.
The target class is updated to include any new methods that are required to satisfy the interface and stub methods containing only the method signature and template are generated in the implementing class.
Click the Close button.
If you click the Close button before you have clicked the Implement button, a message box is displayed, prompting you to confirm that you want to save pending changes before closing the dialog. If you click the No button in the Interface Implementation Mapper message box, your mappings to that interface are not implemented.
Generated stub methods in classes implementing interfaces provide only the method signature and template; that is, they do not provide any implementation details. It is your responsibility to define the appropriate source for each method in the implementing class so that it performs the required action or actions.
In the Interface Options group box on the Miscellaneous sheet of the Preferences or JADE Installation Preferences dialog, if you want:
A compile-time error generated when the stub method is created (that is, it is marked in error in the Methods List of the Class Browser), check the When implementing an interface, do not compile automatically generated stub methods check box.
New interface method names to be generated with the same name as the original interface method name, with no added prefix, check the Generate stub methods without prefix check box.
When you check the Generate stub methods without prefix check box, the Generated stub method prefix text box is disabled and the generated stub methods have the same name as the interface method (unless there is a conflict with an existing name, in which case a number is appended to the name).
To specify the method name prefix that is generated for all new implemented interface methods, specify the prefix that you require in the Generated stub method prefix text box.
When a method is added to the interface, the prefix specified in the user preferences is used unless you check the Generate stub methods without prefix check box, in which case no prefix is used.
These options apply to new implemented interface methods only; that is, they do not affect existing implemented interface method names. For details, see "Maintaining Miscellaneous Options", in Chapter 2.
Stub methods are then automatically generated with body details that you must comment out or remove before the method compiles, as a way of highlighting that you have yet to provide the required method body. For example, you can locate these empty methods by displaying methods in error, to find the methods that you are likely to want to flesh out to make the implementation useful.
To display the interface methods to which a class method is mapped, see "Displaying Interface Methods to which the Selected Method is Mapped", in Chapter 4. See also "Viewing Interface Method Mappings", earlier in this chapter, for details about displaying the implemented methods grouped by the interface or interfaces in which they are defined in the Methods List of the Class Browser.