Interfaces and Types in Java
In Java, you must declare a type for every variable, so we add a fourth principle:
- The set of messages to which an object responds (along with their contracts) is called its interface.
- Interfaces play the role of data types in object-oriented programming.
- The contract for an object-oriented method or function should be expressed in terms of interfaces.
-
The type of every variable should be an interface
(unless the variable is of a primitive type such as
int
orboolean
).
Java compilers do not enforce the last two of those principles, but they are regarded as good OOP, and we require you to follow those principles as part of the coding standards in this course.