I know that placing constants in an interface is usually considered bad practice, but ...
I use the Observer pattern to broadcast events from an object to a listener.
interface DownloadListener { public void sendEvent(int eventId); }
The transmitter uses persistent ints to tell the listener what event has occurred.
class DownloadTask { public static final int EVENT_DOWNLOAD_STARTED = 1; public static final int EVENT_DOWNLOAD_COMPLETED = 2;
Would it be better to place constants inside the interface? I believe that an interface is a contract between a broadcaster and a listener, and therefore it should contain the details (constants) of this contract.
I am developing for mobile devices (Java 1.3), so, unfortunately, you cannot use an enumeration type.
source share