Passing ValueObjects (VO) to View
Perhaps another simple question:
When a Mediator recieves a payload from a custom event dispatched by Model, I can then either:
view.main(payload)
or
view.somesetter = payload
Any preference according to the experts here of the fine Robotlegs ? Are setters okey on Views ? I'm leaning towards the setter approach.
That will be all for today, thanks
Thomas
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
Support Staff 1 Posted by Till Schneidere... on 17 May, 2011 04:48 PM
I don't see any reason why views should be special in any way when it
comes to this decision. Whatever reasons for using or not using
setters you might have fully apply to them.
That being said, my personal rule of thumb is to use setters of
setting the value is the piece of code's main purpose. If, on the
other hand, the value is only something needed to perform whatever
action is invoked, I'd use a method. Of course, this comes down to a
question of encapsulation: How much of what your view is doing with
that value should your mediator know.
As an example, let's say you have sent form data to a server and
received some kind of answer. Depending on what kind of encapsulation
you need/ want, you can either simply set the result, using a setter,
and let the view figure out how (or if) it should be displayed:
`view.formSubmitResult = result;`
or interpret the result and instruct the view to display some kind of feedback:
`view.displayFormSubmitError(error);`
or
`view.displayFormSubmitSuccess();`
2 Posted by thomas.thorsten... on 17 May, 2011 07:05 PM
Yes makes sense, thanks for the reply. In this case, it's a oneoff so I will simply from mediator pass the value to the relevant method. The Mediator doesn't need to know about it further down the line.
Support Staff 3 Posted by Till Schneidere... on 17 May, 2011 07:25 PM
Cool, sounds like a good plan.
cheers,
till