Start of Tutorial > Start of Trail > Start of Lesson |
Search
Feedback Form |
Suppose that you want to add some functionality toStockWatcher
. For instance, suppose that you want to add a method that reports the current stock price, regardless of whether the value changed:However, if you make this change, all classes that implement the oldpublic interface StockWatcher { final String sunTicker = "SUNW"; final String oracleTicker = "ORCL"; final String ciscoTicker = "CSCO"; void valueChanged(String tickerSymbol, double newValue); void currentValue(String tickerSymbol, double newValue); }StockWatcher
interface will break because they dont implement the interface anymore! Programmers relying on this interface will protest loudly.Try to anticipate all uses for your interface up front and specify it completely from the beginning. Given that this is often impossible, you may need either to create more interfaces later or to break your customers code. For example, you could create a
StockWatcher
subinterface calledStockTracker
that declared the new method:Now users of your code can choose to upgrade to the new interface or to stick with the old interface.public interface StockTracker extends StockWatcher { void currentValue(String tickerSymbol, double newValue); }
Start of Tutorial > Start of Trail > Start of Lesson |
Search
Feedback Form |
Copyright 1995-2004 Sun Microsystems, Inc. All rights reserved.