mutiple instatiations of a View class.

andytwoods's Avatar


10 Jul, 2012 05:52 AM

Hi there,

I've reached a point with my RobotLegs learning curve where things are getting awesome! Thanks guys!

I've a question though about an app I'm developing. In View 1 people can click on an object to load up indepth info about that object to edit in a separate View 2 (x,y,z, width height). I really like the idea that they can click on several objects and thus load up several instantiations of View 2 at the same time (each examining a different object). I've a Q or 2!

-I'm storing V2s as VOs in a model. Is this a no no? Got a feeling it is!

-I'm contemplating accessing all instantiations of V2 via a single Mediator (checking some property to then handle the required View). Is this a no no too?

Good to hear your thoughts. Thanks!

  1. 1 Posted by James on 10 Jul, 2012 08:34 AM

    James's Avatar

    Take this with a pinch of salt - I'm not the expert around here!

    A view is a view. A VO is a small immutable container for values, nothing more. You can store VOs in a Model. Instantiating Views and storing them in the Model is a definite nono - avoid at all costs.

    You should be able to use a single mediator for all Views of a particular type. In fact it think I've done it before - it may even be the recommended way, I'm not sure.

  2. 2 Posted by andytwoods on 10 Jul, 2012 08:43 AM

    andytwoods's Avatar

    Just wondering where I store my collection of views though? Ta!

  3. 3 Posted by James on 10 Jul, 2012 09:20 AM

    James's Avatar

    You shouldn't store them anywhere. The whole idea is to decouple your views from everything.

    A view exists on its own and does it's own thing, almost like an independent application. The mediator tells it if something in the application happens that it needs to know about. If something happens within the view that the application needs to be told about, the mediator will tell it.

    Does that help?

  4. 4 Posted by andytwoods on 10 Jul, 2012 09:25 AM

    andytwoods's Avatar

    Wow! RobotLegs is deep! I get this. Thanks for your help!

  5. andytwoods closed this discussion on 10 Jul, 2012 09:25 AM.

  6. Stray re-opened this discussion on 10 Jul, 2012 09:33 AM

  7. Support Staff 5 Posted by Stray on 10 Jul, 2012 09:33 AM

    Stray's Avatar

    If you're talking about where to keep persistent references to views, either for pooling or to preserve state, keep that stuff in your view layer.

    MVCS are packages that refer to purpose, not implementation. So it's reasonable to have a pure-data class inside your view package which is used for pooling / referencing instances of views (so that parent views can then add them).

    As James says - moving those to the model layer would be unusual. However, there are very specific usecases where the model might hold references to views - for example if your app was a sketching app - the sketches could be considered to be part of the model.



  8. Stray closed this discussion on 10 Jul, 2012 09:34 AM.

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