Search code examples
flashapache-flexflex4flex-sparkmediator

Does the Flex4 Host Component have the same function as a view mediator/helper?


Coming from Robotlegs/PureMVC, I am pretty familiar with the concept of the view mediator, i.e. a component that pretty much listens to events/requests coming from the "dummy" view and makes a further request, sends an application-wide signal/event, executes a command, etc, based on the request from the view.

Can the host component idea introduced in Flex 4 be considered a the same as a mediator? The only thing that slightly bothers me is that host components are still considered views, because they extend SkinnableComponent or any of the classes that further inherit from it. In my view, the mediator should be completely left out of view logic.

Nevertheless, I do not want to write a skin, a host component, and a view mediator for that host component, because that would be quite an overhead, and would lead to more complexity rather than abstraction.

Should I use host components as mediators, and put application-level logic there, for instance application level event dispatching?


Solution

  • I am troubled by this in the SkinnableComponent pattern as well. I like my behavior to live in classes that are not view components. I don't even like having references to view components, so I tend to prefer the "Presentation Model" pattern. With SkinnableComponent, the host component is still a view component, but it holds all of the shared behavior. It feels like a bit of a mess and I am not a huge fan of this. I do, however, feel like it is a pretty good way of building re-usable, skinnable components. It is great if you are a component developer, for instance.

    That being said, I find it to be way too complicated to have a Skin, a Host Component and a separated behavior class. Because of this, I tend to just stick with the pattern they gave us (Skin and Host Component) for skinnable components. It makes testing more complicated, in my experience, but it is what it is.

    If I don't need a SkinnableComponent (because I am not generally creating skinnable components for external consumption), I simply use a separated presentation pattern (usually PM) and forgo the skinning pattern.