Interface
- Determines which messages can be received by an object.
- Defines the behaviors that object can perform.
- Lists the methods that object contains.
If two objects accept the same set of messages, they have the same interface.
In Java, this is done through inheritance and interfaces.
Python uses duck typing, but we'll create formal interfaces.
IDrivable Interface
Classes must include a method called
drive
that returns the magnitude of the drive.
IDrivable Interface
Car.drive()
Plane.drive()
GolfBall.drive()
Fundraiser.drive()
All implement the interface, so all can be treated like IDrivable objects!
Multiple Inheritance
public class Car implements IDrivable,
IHeatable, IPlayable {
// code here
}
Java uses interfaces for multiple inheritance