/** * Register a particular <code>ICommand</code> class as the handler for a particular <code> * INotification</code>. * * <p> * * <p>If an <code>ICommand</code> has already been registered to handle <code>INotification</code> * s with this name, it is no longer used, the new <code>ICommand</code> is used instead. * * <p>The Observer for the new ICommand is only created if this the first time an ICommand has * been regisered for this Notification name. * * @param notificationName the name of the <code>Notification</code> * @param command an instance of <code>Command</code> */ public void registerCommand(String notificationName, Class<? extends Command> command) { if (null != commandMap.put(notificationName, command)) { return; } view.registerObserver(notificationName, new BaseObserver(this::executeCommand, this)); }
/** * Remove a previously registered <code>ICommand</code> to <code>INotification</code> mapping. * * @param notificationName the name of the <code>INotification</code> to remove the <code>ICommand * </code> mapping for */ public void removeCommand(String notificationName) { // if the Command is registered... if (hasCommand(notificationName)) { // remove the observer view.removeObserver(notificationName, this); commandMap.remove(notificationName); } }
/** * Initialize the Singleton <code>Controller</code> instance. * * <p> * * <p>Called automatically by the constructor. * * <p> * * <p>Note that if you are using a subclass of <code>View</code> in your application, you should * <i>also</i> subclass <code>Controller</code> and override the <code>initializeController</code> * method in the following way: * * <p><listing> // ensure that the Controller is talking to my IView implementation override * public function initializeController( ) : void { view = MyView.getInstance(); } </listing> */ protected void initializeController() { view = CoreView.getInstance(); }