bool sameName(String name) bool isVotingAge() Date lastVotedOn()
interface Voter { bool sameName(String name); bool isVotingAge(); Date lastVotedOn(); } interface Dictionary<K, V> { public void put(K key, V value); public void delete(K key); public V find(K key); }
class Citizen implements Voter extends Person { bool sameName(String name) { ... } bool isVotingAge() { ... } Date lastVotedOn() { ... } bool isNaturalized() { ... } // and so on }
interface RichVoter extends Voter BigInteger campainContributions();
|
|
interfaceComparable
int compareTo(Object o); public interfaceDestroyable
void destroy(); boolean isDestroyed(); public interfaceReadable
int read(CharBuffer
cb);
class Card implementsComparable
int compareTo(Object o) { ... } // and so on. class SecurityCertificate implementsDestroyable
,Readable
void destroy() { ... } boolean isDestroyed() { ... } int read(CharBuffer cb) { ... } // and so on.
boolean beats(Comparable
x) { ... } void validate(Destroyable
tag) { ... } Message read(Readable
input) { ... }
SecurityCertificate ticket = new SecurityCertificate() validate(ticket) Message m = read(ticket)