The Java Platform Java Runtime Environment Data Types Control Statemets Methods Arrays Classes and Objects Inheritance Constructor Interface![]() Interface![]() Interface Example![]() Interfaces and coupling![]() The Java XML package![]() The Java IO Serializable interface![]() Using Interface Packages & Access Modifiers Java Collections Framework | Interface Examplepublic interface StockServer { final static int SOME_CONSTANT = 9999; StockServer(); void addClient(StockClient client); void removeClient(StockClient client); ... } The StockServer interface defines a constant, SOME_CONSTANT, a constructor and two methods. This represents a contract/API of classes that implements the StockServer interface. public interface StockClient {
void updateChange(String tickerSymbol, double newValue);
}The StockClient interface represent clients of the StockServer implementation classes. Together, the StockServer and the StockClient allows any StockClient implementation classes to work with any StockServer implementation. class StockQuoteApplication implements StockClient {
void updateChange(String tickerSymbol, double newValue) {
.... // Display the new information
}
}class StockTraderApplication implements StockClient {
void updateChange(String tickerSymbol, double newValue) {
.... // Place sell or buy order
}
}
|