package com.ahrooga.puremvc.as3.multicore.patterns.mediator { import org.puremvc.as3.multicore.interfaces.*; import org.puremvc.as3.multicore.patterns.observer.Notifier; import org.puremvc.as3.multicore.patterns.mediator.Mediator; public class AbstractMediator extends Mediator implements IMediator { private var methodMap:Object; public function AbstractMediator( mediatorName:String = null, viewComponent:Object = null ) { methodMap = new Object(); super(mediatorName, viewComponent); } /* * When extending from this class please note that calling registerNotificationHandler MUST be * called from the extended class' constructor. */ protected function registerNotificationHandler(notificationName:String, handlerMethod:Function):void { methodMap[notificationName] = handlerMethod; } override public function listNotificationInterests():Array { var interests:Array = new Array(); for (var key:String in methodMap) { interests.push(key); } return interests; } override public function handleNotification( notification:INotification ):void { /* I am only passing the INotification body object to the handler method. * You may also wish to pass the type ( notification.getType() ). */ methodMap[ notification.getName() ]( notification.getBody()); }; } }