Mapping Services

harold.martin's Avatar


30 Jul, 2013 04:46 PM

Hi everybody,

I come again to ask a conceptual question :

Lets take a look to the MVCS attached schemes.
For a large program application I create a ISocketService which expose some methods like connect, disconnect, sendDatas... I wrote an AbstractSocketService implementing all the stuff. I use ISignalCommandMap to map signals to those functions.

Until then all is right but I try to implements 2 (or more) different classes that generalize the AbstractSocketService (PrinterSocketService and ToolSocketService)

I don't want to have several commands (ConnectPrinterCommand, ConnectToolCommand... ) it's why I choose this design but I don't understand how to map correctly the 2 different services with same commands...

Should I create 2 different contexts with 2 configs? Perhaps with some modules?
Can you tell me if my approach is good or if I'm totally in the wrong way.

Thx in advance for advices .

  1. Support Staff 1 Posted by Ondina D.F. on 02 Aug, 2013 04:39 PM

    Ondina D.F.'s Avatar

    Hi Harold,

    I'm truly sorry for the delay in responding!
    It looks like each of us, support staffers, has been busy.

    Very nice diagrams :)

    I'd prefer to have separate commands for different actions ( print, load something, save something).

    My advice is to avoid having a single command that has to decide which service to use ( probably depending on some kind of flag from the signal's payload), especially when there are more than 2 services. You'll end up having long switch/if statements in your execute method, and depending on how you map your services, you might need to inject several services into one command, whilst you actually need just one of them at a time.

    Alternatively, you could inject a dictionary or a collection of your choice into your command, that contains the services. It is just an idea, I haven't tried it out yet. I'll have to think about it a little more to see whether it's a good approach or not, or whether I'd used it in my commands.


    var toolService:ToolSocketService = injector.getOrCreateNewInstance(ToolSocketService);
    var printService:PrintSocketService = injector.getOrCreateNewInstance(PrintSocketService);
    services["print"] = printService;
    services["tool"] = toolService;, "services").toValue(services);


    [Inject (name="services")]
    public var services:Dictionary;
    public function execute():void

    vo.service is the VO that the signal carries.

    Btw, how are you currently mapping your services and how are you injecting them into commands?


  2. 2 Posted by harold.martin on 03 Aug, 2013 10:51 AM

    harold.martin's Avatar

    Hi Ondina,
    Thx for the answer, everybody is in holidays? :-)
    No problem for the delay, It's enable me to search by myself solutions, and the project maturate.

    I like your second solution, injecting dictionary into command. I will try it!
    Finally the stuff I'm looking for is a kind of polymorphism mechanism?
    To enable the possibility to map a service depending on the type of the value object.

    During this few days I have discovered some pretty things like extensions and bundles.
    My idea is to have 2 different contexts (PrinterContext and ToolContext) with different mappings. I began to write an SocketServiceExtension but I don't know where to put my classes...
    I know there is 3 packages (api, dsl, impl) but where I can put my classes correctly I don't.

    I do this tree :

    + socketService
       - SocketServiceExtension
       + api
          - ISocketService
       + dsl
          - SocketServiceEvent
          - SocketServiceRequestEvent
          - ISocketDevice
       + impl
          - AbstractSocketService
          - ConnectDeviceCommand
          - DisconnectDeviceCommand
          - SendDatasToDeviceCommand
    I think I'm not right but I don't know what I should to put in the extension and what I should to put in my bundle...
  3. Support Staff 3 Posted by Ondina D.F. on 03 Aug, 2013 01:35 PM

    Ondina D.F.'s Avatar

    Hey Harold,

    Are you sure you want to create an extension for your abstract service and commands, or your intention was to have a library shared between different contexts, where you put the common classes?

    If you really want to have an extension, then, I think, you'd have to create some sort of a SocketServiceMap, where you add the services and/or commands and map them in there.

    public class SocketServiceExtension implements IExtension
        public function extend(context:IContext):void

    After you install your extension in each context, you inject IServiceSocketMap into a config file and you call something like:

    serviceSocketMap.addService("print", PrintSocketService);
    serviceSocketMap.addService("tool", ToolSocketService);

    where the first parameter would be the key in your services dictionary, and the second the service class you need in that particular context.

    So, your extension would contain only the "shared" classes and would be used just to wire things together.


  4. 4 Posted by harold.martin on 05 Aug, 2013 11:51 AM

    harold.martin's Avatar

    Hi Ondina,
    I'm not sure I understand the main purpose of extensions... Yes I don't need extension but only a shared library.

    I've work hard to write this library this weekend, and it's time to share my work :-)

    I try some examples, and it seems to work correctly.

    Attached you can find :

    - RobotlegsSignalCommandMapExtension.swc (SignalCommandMapExtension compatible with robotlegs v2.1.0)
    - (sources + swc)
    - SocketServiceLibDiagram.png (The classes diagramm of SocketServiceLib)
    Can you tell me what you thing about this.

    Thx a lot.

  5. Support Staff 5 Posted by Ondina D.F. on 05 Aug, 2013 02:53 PM

    Ondina D.F.'s Avatar

    Hey Harold,

    I had a quick look at your lib.
    Yes, I can see that you put a lot of work into it!
    It looks very good, so far :)


  6. Ondina D.F. closed this discussion on 23 Sep, 2013 02:34 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