View vs Mediator responsibilities for adding children

Stray's Avatar

Stray

01 Mar, 2010 08:44 PM

I've noticed that I'm being inconsistent in how I add new child view classes to a mediated view, and wondered what others prefer.

Specifically, this is where

1) The child view is being added in response to an event - for example, a roll over of one element causes a different element to display a sprite which shows some text information.

2) The view being mediated is essentially 'dumb' - it has no code in it currently, and is just the appropriate container for this child.

In some cases I'm doing the adding in the mediator itself (via the handler for the event):

  view.addChild( new Whatever ( whateverLabel ) );

In other cases I'm putting the addChild functionality in the view and simply calling it from the mediator:

  view.showTheWhatever( whateverLabel );

I know this is a pretty basic question - but is there a Robotlegs reason why I should prefer one over the other?

For example, when the view / mediator mappings are created, is there a performance hit / advantage either way?

  1. Support Staff 1 Posted by Joel Hooks on 01 Mar, 2010 09:01 PM

    Joel Hooks's Avatar

    I like to do the latter myself. Kinda the same thing I suppose.

  2. Support Staff 2 Posted by Stray on 01 Mar, 2010 09:08 PM

    Stray's Avatar

    Thanks Joel - my preference is for the latter as well - I just get lazy sometimes... (don't we all?) but it made me wonder about whether the framework finds either to be more work...

  3. Support Staff 3 Posted by Shaun Smith on 02 Mar, 2010 07:28 AM

    Shaun Smith's Avatar

    I do the first if I'm in a rush, and usually refactor to the second later. I doubt there is any performance difference between the two at all.

  4. Stray closed this discussion on 16 Feb, 2011 09:03 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