Interfaces can be used as Classes in type specification
Interfaces behave exactly as classes when used as a type.
The normal type declaration syntax "interfaceName variableName" declares a variable or parameter to be an instance of some class that implements interfaceName.
- public class StudentBody {
- Stream s;
- Picture id_photo; // of interface storable
- StudentRecord id_card; // of interface storable
- . . .
- public void register() {
- save(id_photo);
- save(id_card);
- }
- public void save(Storable o) {
- o.store(s);
- }
- }