Wrapping RL application as component

Vj3k0's Avatar

Vj3k0

21 Aug, 2012 06:59 AM

Hi guys, I would appreciate your advice on one issue I'm having.

I want to break big application to simpler components using RL. So I would create multiple components all created with RL framework and export them as SWC. Now, I need to wire things up. What I want is to decouple component as much as possible. In ideal case, I would use component interface, which I would use to input data in it, and events from component to output data from it.

The problem is that I would then need to do a extra work on main document class of the component because it would need to implement my interface.

What would you guys do in my shoes?

Regards,
Vjeko

  1. Support Staff 1 Posted by Ondina D.F. on 21 Aug, 2012 07:45 AM

    Ondina D.F.'s Avatar

    Hi Vjekoslav,

    So I would create multiple components all created with RL framework and export them as SWC.

    This sounds like a library project to me.
    You add the components to a library project, and then you add it to your project’s library path.
    In case you don’t know how to do this, here are more details:
    http://livedocs.adobe.com/flex/3/html/projects_7.html

    Then you can use/wire your components like any other components in your Robotlegs application.

    Or are you talking about modules?

    Ondina

  2. 2 Posted by Vj3k0 on 21 Aug, 2012 08:30 AM

    Vj3k0's Avatar

    Thanks for your reply.

    I know how to work with libraries, that's not what I'm interested.

    Let me explain in detail with examples. Component could provide either some functionality (i.e. supporting component for communication with web service) or can be collection of visual elements providing some functionality (i.e. custom notification pop-up).
    What service component will do is relay request to web service, validate response and dispatch event which will contain result. To send message (to use component) you would call method send(message:XML) from IService interface.
    What notification component will do is present notification window, wait for user input to confirm that notification (like clicking ok or close button) and in the end dispatch event which will mark that notification was completed. To show notification you would call method notify(text:String) from INotification interface.

    I know how would I wire things up with RL in my application to include this service and notification, but what I'm not sure is how would I actually create this components using RL. My question is where do I implement this interfaces and provide the usability of components like I described in example.

    Regards,
    Vjeko

  3. Support Staff 3 Posted by Ondina D.F. on 21 Aug, 2012 08:47 AM

    Ondina D.F.'s Avatar

    I hope this time I understand what you are looking for :)

    In robotlegs v.1 :

    -The Service class:

    public class SomeService extends Actor implements ISomeService

    -Mapping:

    injector.map(ISomeService).toSingleton(SomeService);

    -In a class (for example in a Command) where you need the service:

    [Inject] public var someService: ISomeService;

    someService.send(message)

    But, if you know this too, then I really don’t know what you mean.

  4. Support Staff 4 Posted by Ondina D.F. on 21 Aug, 2012 08:50 AM

    Ondina D.F.'s Avatar

    Sorry, I used the robotlegs v2 mapping style in my previous post.

    Here for robotlegs v. 1:
    injector.mapSingletonOf(ISomeService, SomeService);

  5. Support Staff 5 Posted by Ondina D.F. on 21 Aug, 2012 09:11 AM

    Ondina D.F.'s Avatar

    Since SomeService extends Actor, it is able to dispatch custom events on the shared EventDispatcher provided by the robotlegs context.

    Commands, Mediators, Models and Services (extending Actor), they all have access to that shared event dispatcher.

    But, as you can see here: http://knowledge.robotlegs.org/kb/reference-mvcs-implementation/do-...

    you don’t have to extend Actor.

    Sorry, if you knew this too. Maybe I’m totally missing the point :)

  6. 6 Posted by Vj3k0 on 21 Aug, 2012 09:17 AM

    Vj3k0's Avatar

    Hehe, you're getting there.

    I'll be using RL1 convention since I'm more familiar with it, but the problem should be the same for RL2.

    Suppose you create your application like you did here. But when you're done, you pack it in SWC and want to provide one interface for it.
    So for your service you have structure like:
    - ServiceContext - ServiceComponent - commands - SendMessage - ReformatMessage - ... - model - ServiceModel - vo

      - SomeValueObject
      - ...
    
    • service
      • Service
      • dto
        • SomeDTO
        • ...
    • views
      • (nothing here for this)

    So to create a component, I would have as document class ServiceComponent. In there I would create context, etc... Now I have finished project all cool with asdocs, fancy formatting and tested, and now I want to wrap as SWC so that I can use it somewhere else (doesn't need to be RL project).

    So when I have this SWC, I want to treat it as full thoroughbred component - black box. There is only one input and that is through IService interface. There may be multiple outputs which are relayed through events.

    So if I want to use this SWC created with RL in non-RL application I would have to create and instance of this and use it through this IService interface:
    var service:IService = new ServiceComponent();
    service.send(someMessage);

    Now I have a problem because for this to work that would mean that ServiceComponent should implement IService interface (to remind you ServiceComponent is document class which holds component context).

    Don't know how much more could I describe it. :-)

  7. 7 Posted by Vj3k0 on 21 Aug, 2012 09:21 AM

    Vj3k0's Avatar

    Sorry about formatting issue, it represents project structure:

    • ServiceContext
    • ServiceComponent
    • commands
      • SendMessage
      • ReformatMessage
      • ...
    • model
      • ServiceModel
      • vo
        • SomeValueObject
        • ...
    • service
      • Service
      • dto
        • SomeDTO
        • ...
    • views
      • (nothing here for this)
  8. Support Staff 8 Posted by Ondina D.F. on 21 Aug, 2012 10:15 AM

    Ondina D.F.'s Avatar

    Vjeko , I’ll have to think about this and answer later, when I’ll have more time, but just now all I can come up with is having an interface for your ServiceComponent which would be mediated by a ServiceComponentMediator, which would handle the request for a service call coming from the main application.

    Till later.

  9. 9 Posted by Vj3k0 on 21 Aug, 2012 11:02 AM

    Vj3k0's Avatar

    That was my thinking also, glad you understood my problem. :-)

  10. Support Staff 10 Posted by Ondina D.F. on 21 Aug, 2012 11:11 AM

    Ondina D.F.'s Avatar

    That was my thinking also, glad you understood my problem. :-)

    Oh well, I might be a little slow today..

    Another possibility would be to use a shared event dispatcher between the main app and your swc.

  11. Support Staff 11 Posted by Ondina D.F. on 21 Aug, 2012 03:39 PM

    Ondina D.F.'s Avatar

    To sum it up, here are the possibilities that I know of:

    • Use the Modular Utility to communicate between 2 rl apps (not your case)
    • Robotlegs swcs as a library project, mappings in the main app’s context (not your case)
    • Loading Robotlegs swc into a non-robotlegs application:
      • Communicate between main and swc through an interface that the document class (or root view) of your swc implements, and let its mediator communicate with commands, services etc
      • Define a shared event dispatcher (either set the dispatcher of the subapp to be main’s dispatcher or vice versa)
      • In your swc’s  Context (or a Command responsible for mappings) map IMainView to MainViewMediator. Bad names, I know. In your main application, the component (SomeMainView) wanting to call the service from your swc implements IMainView interface. When this view dispatches an event, MainViewMediator(in your swc), who’s listening fort hat event, dispatches an event to trigger a command->service etc. The swc’s root/document class creates its Context with the main application’s view (SomeMainView) as the contextView.

    My preference would be interfaces and shared event dispatcher.

  12. 12 Posted by Vj3k0 on 22 Aug, 2012 06:24 AM

    Vj3k0's Avatar

    Thanks for your suggestions.

    I'm gonna comment on your 3rd point of loading RL swc in non-RL application.
    1. This was my suggestion also, so no point in commenting that.
    2. Interesting as a thought, but I don't see it working in non-RL application since they are not oriented to work around single event bus. This way, I would have to have exposed this event dispatcher somewhere in the code, instead of having only component. It also creates coupling.
    3. This will create really tight coupling, not to mention that if I have component which has 50 methods and properties exposed through interface, each application in which I would use this component would have to implement all 50 of them. Also if view is mapped to my main application that would mean that it needs to dispatch all events for mediator to catch them.

    I'm open to other suggestions also. :-)

    P.S. Ondina, thanks for your prompt help.

  13. Support Staff 13 Posted by Ondina D.F. on 22 Aug, 2012 11:29 AM

    Ondina D.F.'s Avatar

    Hi Vjeko,

    You’re welcome! Interesting discussion.

    As we all know, the components in the Flex SDK make use of data fields, data functions, data descriptors, and object factories and they dispatch events containing the return data.
    Accessing components through their API of events, properties, methods, or defining interfaces are the most common ways of building them loosely coupled and keeping them encapsulated.
    But, it sounds like you think that using APIs, Interfaces, or shared event dispatchers would break the encapsulation of your components in a way or another, or that you had to do extra work on the component level, and therefore that you need another solution :)

    I'm open to other suggestions also. :-)

    Me too!

    Cheers,
    Ondina

  14. Support Staff 14 Posted by Ondina D.F. on 22 Aug, 2012 12:13 PM

    Ondina D.F.'s Avatar

    JFYI:
    Not directly related to this discussion, and also not a solution to your problem, but I thought you might be interested in the concept of an “anti corruption layer“, that Shaun mentioned in this post:
    http://knowledge.robotlegs.org/discussions/robotlegs-2/38-service-w...

    http://moffdub.wordpress.com/2008/09/21/anatomy-of-an-anti-corrupti...
    http://moffdub.wordpress.com/2008/09/24/anatomy-of-an-anti-corrupti...

  15. Ondina D.F. closed this discussion on 25 Aug, 2012 01:10 PM.

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