Contracts/APIs

Every class is characterized by a contract that specifies the behavior of its methods -- that is, how instances of the class respond to messages. For each method, the contract specifies:

(There are additional aspects of the contract that we are intentionally ignoring for the time being.)

The contract defines an abstraction barrier between the users and the implementors of the class. A user of the class can expect that objects will behave as described in the contract, but cannot expect anything more than what is specified in the contract. An implementor of the class must ensure that objects fulfill the contract, but need not implement anything more than what is specified in the contract.

In the programming community, another term for a contract is an Application Programming Interface (API). An API is the documentation that allows programmers to use the components of a software library as black-box abstractions. It turns out that every class in Java is a library component that is described by an API. The API for the entire 1.0.2 version of Java can be found here; the API for the window system (of which Graphics is a member) can be found here.

The Java API can be daunting for the uninitiated. We have provided simplified contracts for some of the classes you need when programming graphics applets: