Interfaces: Changing Functions

Package

Interfaces can be used for the sames purposes as function pointers in C++. Pointers to functions are not allowed in Java. Therefore, when a function needs to be transported, we have to embed it in a class. Often, such a function may need to have its functionality changed. For example, a find function may need to change from finding records based on names to finding records based on social security numbers. This can be accomplished easily in Java if classes implementing specific variations of the function implement a common interface. This example illustrates how this is done. Click here for the code.

Enter a name, social security number, and wages, select Add DB, and click on Do It! to add the record to the data base. Erase the name, enter hours, select Set Hours, and click on Do It!. Select Worker Info and click on Do It!. The information should be correctly stated because the original search for the appropriate record to update was made based on social security number. Repeat the above except erase social security number and enter a name. The same result should be obtained.