Filed under: cairngorm
I have been using Cairngorm for a little under one year both in Flex 1.5 and Flex 2.0, in various projects of varying scopes. There are a few questions that have come up but have never had any ‘real’ answer from another person. Some of the following questions may overlap or simply be rephrased differently. I will also follow up
- At what point in the command structure is data ‘injected’? This may seem painfully obvious in theory but in execution it can be somewhat unclear. Depending on the type of application, who is calling (or rather who is dispatching an event that the Controller listens to), what level of complexity of data, etc.. The point is that typically the event’s data is ‘injected’ at the UI level. For example, we would take certain data values from comboBoxes, numericSteppers, etc. to add to a ValueObject to pass as the data of the event. I will come back to this point later
- Is there a hierarchy for who handles the data passed through the command chain? Again, maybe it is painfully obvious, but again, depending on the situation who does the bulk of the ‘data creation’ versus who does a little bit of ‘data massaging’. I would suggest that indeed there is a hierarchy. UI => Command => Delegate. You may be thinking, well of course that is the order but I have a few issues with this order. For instance, let’s say you have a view dispatch an event, passing many parameters needed for the call, but you also have to grab some one piece of data from your model. Some may suggest that you would simply create the VO with the needed data in the UI, pass the parameters in the CairngormEvent (or subclass), then take those values in the command, and then pass it to the delegate which gets passed as the call param. This just doesn’t settle well with me. Firstly I don’t like having the UI getting things from the model to add to the UI. It should only be concerned with the data within the view itself. In this situation, I’d prefer to have the VO to begin its life in the UI, get passed to the command via the event.data, then the command ‘massages’ the VO by getting what is needed from the model before getting passed to the delegate. That way the VO’s life span is for the whole execution part of the event/command but you don’t have the UI peeking into the model. Is that wrong to feel that way?
- Should the UI be able to peer into the model for the needed data to pass with the event? Touching on the point above, I would say no but I would enjoy others’ input.
Maybe I am just way to anal about this but I think it is important to at least establish some good ‘rules of thumb’. It seems that when I bring this up with my coworkers, they haven’t given it much thought but agree that it should be a topic of discussion. Of course going down this route means that the developer would have to make good use of extending the CairngormEvent and also creating the respective ValueObject subclasses. If you simply pass generic objects, then you defeat the purpose of being able to ‘massage’ the data carefully. Plus you loose Flex 2’s ability to give code hints for the parameters.
J
