/home/wpollock1/public_html/AJava/IfaceDemo/Sellable.java
package com.wpollock.iface;
/**
* The Sellable interface from the GiftBasket demo has two methods,
* cost and describe; here, we add a third method to that interface.
*
* To prevent old code such as GiftBasket.java from breaking when we
* add methods to interfaces it uses, we must also add a "default"
* implementation of this method.
*
* @author Wayne Pollock, Tampa Florida USA
*
*/
public interface Sellable {
/**
* Compute the cost of a Sellable item
* @return the price of a Sellable item
*/
float cost();
/**
* Print to System.out a description of a Sellable item.
* (This is a bad design; the method should return a String instead.)
*/
void describe ();
/**
* Sellable items may have tax computed. This is the default rate.
* (In an interface, all variables are automatically public, static,
* and final.)
*/
double DEFAULT_TAX_RATE = 0.07;
/**
* Compute the tax to be collected on a Sellable item. Not all such
* items have tax. Since this is a new method for an existing
* interface, we need to provide a default implementation.
*
* @return The tax to be collected, in U.S. dollars.
*/
default double tax() {
return DEFAULT_TAX_RATE * cost();
}
/*
* Interfaces can have nested classes or other interfaces, not shown here.
* Additionally, interfaces can contain static methods; these are
* useful for related "utility" methods that otherwise would need to be
* put in some other class.
*/
}