Data(Actor) interface in Mediator and Implements in Command.

rock57's Avatar

rock57

28 Mar, 2013 03:04 AM

public interface IUserProxy
{
function get name():string;
}

public interface UserProxy extends Actor implements IUserProxy
{
private var _name:string;
public function get name():string
{
return _name;
}

public function set name(value:string):void
{
_name = value;
}
}

ok, let's injector.mapSingletonOf(IUserProxy, UserProxy);

now, in Command like this
var userProxy:UserProxy = inject.getInstance(IUserProxy);
command could access set and get method

in Mediator like this

[Inject]
public var userProxy:IUserProxy

so, mediator just could access get method

BUT! sometime someone need set something to UserProxy in Mediator, they could do this

var userProxyImpl:UserProxy = userProxy as UserProxy;

... userProxy's interface is invalid...

i need a way that Mediator could't access set method... anyone run into this problem?

  1. Support Staff 1 Posted by Ondina D.F. on 28 Mar, 2013 10:03 AM

    Ondina D.F.'s Avatar

    Hello,

    You can let your UserProxy implement 2 interfaces. In my example below AnotherModel implements IAnotherModelGetter, IAnotherModelSetter.

    Mappings:

    injector.mapSingletonOf(IAnotherModelGetter, AnotherModel);
    injector.mapSingletonOf(IAnotherModelSetter, AnotherModel);
    

    Model implementing 2 interfaces:

    public class AnotherModel extends Actor implements IAnotherModelGetter, IAnotherModelSetter
    {
        private var _name:String;
        public function AnotherModel()
        {
        }
    
        public function set name(value:String):void
        {
            _name = value;
            dispatch(new SomeEvent(SomeEvent.DATA_CHANGED, name));
        }
    
        public function get name():String
        {
            return _name;
        }
    }
    

    Interfaces:

    public interface IAnotherModelSetter
    {
        function set name(value:String):void;
    }
    
    public interface IAnotherModelGetter
    {
        function get name():String;
    }
    

    Command:

    public class AnotherCommand extends Command
    {
        [Inject]
        public var anotherModel:IAnotherModelSetter;        
        
        override public function execute():void
        {           
            anotherModel.name="something";
        }
    }
    

    Mediator:

    [Inject]
    public var anotherModel:IAnotherModelGetter;
    
    …
    trace(anotherModel.name);
    

    Did that help?

    Note: search discussions on this forum for „inject model into mediator“, to see why it is not always a good idea to inject models into mediators.

    Ondina

  2. Support Staff 2 Posted by Ondina D.F. on 08 Apr, 2013 10:05 AM

    Ondina D.F.'s Avatar

    I hope you solved your problem.
    Closing the thread.
    If you need more help with this, feel free to re-open this discussion. Please open new threads for new issues.

  3. Ondina D.F. closed this discussion on 08 Apr, 2013 10:05 AM.

Comments are currently closed for this discussion. You can start a new one.

Keyboard shortcuts

Generic

? Show this help
ESC Blurs the current field

Comment Form

r Focus the comment reply box
^ + ↩ Submit the comment

You can use Command ⌘ instead of Control ^ on Mac