Mapping a PresentationModel as an Interface and as its own type

Max's Avatar


09 Feb, 2010 03:30 AM


I'm diving in to Robotlegs and want to Inject my PresentationModel MainPModel into my view as its corresponding interface IMainPModel. That's quite easily accomplished via this line in my Context startup() method:

injector.mapSingletonOf(IMainPModel, MainPModel);

and then a corresponding getter / setter pair in my view:

public function get model():IMainPModel...
public function set model( value:IMainPModel ):void...

Now I want the rest of my application, specifically the commands to see MainPModel not as IMainPModel but as its own type. I am tempted to put this additional line in my context startup() method:


The fun caveat is that I'd like both mappings to refer to the same instance framework-managed-singleton in memory and I'd rather not resort to named-mapping (I'm not a fan of magic strings).

My questions are:
1. Is this possible?
2. Is this design silly, and if so, why?

  1. Support Staff 1 Posted by Shaun Smith on 09 Feb, 2010 05:58 AM

    Shaun Smith's Avatar

    There are a couple of ways to go about this.

    Use mapValue for the second definition:

    injector.mapValue(IMainPModel, injector.instantiate(MainPModel));

    Use mapRule:

    var rule:* = injector.mapSingleton(MainPModel);
    injector.mapRule(IMainPModel, rule);

    I haven't tested either of those, but I believe they should do the trick.

    As for whether or not the design is silly: I'm not sure why you need access to the concrete type when you could just use the interface. "Program to interfaces not concretions" comes to mind :)

  2. Support Staff 2 Posted by Joel Hooks on 09 Feb, 2010 06:00 AM

    Joel Hooks's Avatar

    I believe Max is going for a read-only interface on his view.

  3. 3 Posted by Max on 09 Feb, 2010 02:17 PM

    Max's Avatar

    You are both right. @Joel - you're right in that my goal is to expose a restricted set of the presentation-model's functionality to the view and a greater set to the controller / commands. @Shaun - it is also true that a cleaner way to accomplish this would be to make an additional interface for that greater set of functionality. The presentation-model would implement two interfaces. Thanks for the help and suggestions.

  4. 4 Posted by Max on 09 Feb, 2010 04:28 PM

    Max's Avatar

    My silly example is up at: Thanks for your help.

  5. Till Schneidereit closed this discussion on 02 Mar, 2010 12:46 PM.

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

Keyboard shortcuts


? 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