Product Information > JADE Development Environment User’s Guide > Chapter 14 - Adding and Maintaining Interfaces > Implementing an Interface

Implementing an Interface

For a class to implement an interface, it must:

  1. Indicate that it wants to use a specific interface

  2. 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

  1. In the Class List of the Class Browser, select the class that is to use the interface.

  2. Select the Interface Mapping command from the Classes menu.

    The Interface Implementation Mapper dialog is then displayed.

  3. 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 text editor in the middle of the dialog, as shown in the following diagram.

  4. 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).

  5. 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.

  6. If you want add a method prefix to all mapped method names, perform the following actions.

    1. Ensure that the Add Method Prefix value is displayed in the Modifier list box (the default value).

    2. 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.

    3. Click the Modify button.

  7. To remove a method prefix from all mapped methods, perform the following actions.

    1. Select the Remove Method Prefix value in the Modifier list box.

    2. Specify the value in the Value text box that you want to remove from all JADE methods that are mapped to the interface.

    3. 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.

  8. 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.

  9. 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:

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.