org.puremvc.java.interfaces
Interface IMediator

All Known Implementing Classes:
Mediator

public interface IMediator

The interface definition for a PureMVC Mediator.

In PureMVC, IMediator implementors assume these responsibilities:

Additionally, IMediators typically:

When an IMediator is registered with the IView, the IView will call the IMediator's listNotificationInterests method. The IMediator will return an Array of INotification names which it wishes to be notified about.

The IView will then create an Observer object encapsulating that IMediator's (handleNotification) method and register it as an Observer for each INotification name returned by listNotificationInterests.

A concrete IMediator implementor usually looks something like this:

import org.puremvc.patterns.mediator.~~; import org.puremvc.patterns.observer.~~; import org.puremvc.core.view.~~; import com.me.myapp.model.~~; import com.me.myapp.view.~~; import com.me.myapp.controller.~~; import mx.controls.ComboBox; import mx.events.ListEvent; public class MyMediator extends Mediator implements IMediator { public function MyComboMediator( viewComponent:Object ) { super( viewComponent ); combo.addEventListener( Event.CHANGE, onChange ); } public function listNotificationInterests():Array { return [ MyFacade.SET_SELECTION, MyFacade.SET_DATAPROVIDER ]; } public function handleNotification( notification:INotification ):void { switch ( notification.getName() ) { case MyFacade.SET_SELECTION: setSelection(notification); break; case MyFacade.SET_DATAPROVIDER: setDataProvider(notification); break; } } // Set the data provider of the combo box private function setDataProvider( notification:INotification ):void { combo.dataProvider = notification.getBody() as Array; } // Invoked when the combo box dispatches a change event, we send a // notification with the private function onChange(event:ListEvent):void { sendNotification( MyFacade.MYCOMBO_CHANGED, this ); } // A private getter for accessing the view object by class private function get combo():ComboBox { return view as ComboBox; } }

See Also:
INotification

Method Summary
 java.lang.String getMediatorName()
          Get the IMediator instance name
 java.lang.Object getViewComponent()
          Get the IMediator's view component.
 void handleNotification(INotification notification)
          Handle an INotification.
 java.lang.String[] listNotificationInterests()
          List INotification interests.
 void setViewComponent(java.lang.Object viewComponent)
          Set the IMediator's view component.
 

Method Detail

getMediatorName

java.lang.String getMediatorName()
Get the IMediator instance name

Returns:
the IMediator instance name

getViewComponent

java.lang.Object getViewComponent()
Get the IMediator's view component.

Returns:
Object the view component

setViewComponent

void setViewComponent(java.lang.Object viewComponent)
Set the IMediator's view component.

Parameters:
viewComponent -

listNotificationInterests

java.lang.String[] listNotificationInterests()
List INotification interests.

Returns:
an Array of the INotification names this IMediator has an interest in.

handleNotification

void handleNotification(INotification notification)
Handle an INotification.

Parameters:
notification - the INotification to be handled