/* * @(#) Notifiable.java - Interface for custom observer agents. * (c) 2000 Ivan Maidanski http://ivmai.chat.ru * Freeware class library sources. All rights reserved. ** * Language: Java [pure] * Tested with: JDK v1.1.6 * Last modified: 2000-12-25 10:15:00 GMT+03:00 */ /* * This software is the proprietary information of the author. ** * Permission to use, copy, and distribute this software and its * documentation for non-commercial purposes and without fee is * hereby granted provided that this copyright notice appears in all * copies. ** * This software should not be modified in any way; any found bug * should be reported to the author. ** * The author disclaims all warranties with regard to this software, * including all implied warranties of merchantability and fitness. * In no event shall the author be liable for any special, indirect * or consequential damages or any damages whatsoever resulting from * loss of use, data or profits, whether in an action of contract, * negligence or other tortuous action, arising out of or in * connection with the use or performance of this software. */ package ivmai.util; /** * Interface for custom observer agents. ** * A class should implement (or should have a private class which * implements) this interface when it wants to be informed of * changes in the observable object. Normally, observer agent serves * as an intermediate entity between one or more observed entities * and the application entity which wants to be notified (with * details) only on the events in these observed objects. * Verifiable interface is extended to allow integrity * checking for typical agent objects. Important notes: agents must * not modify observed object anyhow; notification should * be performed just after changes; this notification mechanism has * nothing to do with threads and is completely separate from the * 'wait-notify' mechanism of Object. Here is the usage * example of an observer agent: ** *
 * final class MyAgent // hidden helper class
 * implements Notifiable
 * {
 * private final MyClass myClass; // myClass != null
 * protected MyAgent(MyClass myClass)
 * throws NullPointerException
 * {
 * myClass.equals(myClass);
 * this.myClass = myClass;
 * }
 * public void update(MultiObservable observed, Object argument)
 * {
 * MyClass myClass = this.myClass;
 * if (argument instanceof MyEvent && myClass.observed == observed)
 * // safe (private) actions on myClass
 * }
 * public void integrityCheck()
 * {
 * if (myClass == null)
 * throw new InternalError("myClass: null");
 * }
 * }
 * private transient Notifiable agent = new MyAgent(this);
 * . . .
 * observed.addObserver(agent);
 * . . .
 * observed.removeObserver(agent); // stop observing
 * 
** * @see MultiObservable ** * @version 2.0 * @author Ivan Maidanski */ public interface Notifiable extends Verifiable { /** * Notifies this observer agent on a particular event * that just occurred. ** * This method is called whenever observed object is * changed. Important notes: observed object should not * be modified during the notification; types of observed * and argument should be checked inside; no access * should be provided to the instance of this interface (since this * method is public) outside hidden * notifyObservers method of observed * object; RuntimeException (and * OutOfMemoryError) may be thrown if a notification * failure has occurred. ** * @param observed * the observed object (may be null, should be checked * inside). * @param argument * the argument (may be null, should be checked inside) * describing the occurred event. * @exception RuntimeException * if the notification process has failed (a custom exception). * @exception OutOfMemoryError * if there is not enough memory (to perform notification). */ public abstract void update(MultiObservable observed, Object argument); }