Object-Oriented Views
Summary
I’ve seen this too many times in views (grails, ruby-on-rails, velocity)
#if ($user.hasPicture())
#parse (“userPicture”)
#else
## do nothing
#endif
or even worse:
# if ( $user != null)
# show user information
#endif
I mean, didn’t we just study Object Orientation to use polymorphism just for that sort of thing.
What if.
What if we’d get a proper User representation from the domain. Whether it is a user with or without a picture, or if it is a NullObject (UserThatDoesNotExistInSystem), the details don’t need to pollute the views.
In this talk, I will show one possible solution for case like that – getting a User representation from the domain and displaying relevant information in web views. The information rendered in UI differs based on whether user exists or not, it’s data and whether the user is being edited or is only to be viewed.
The patterns used in the code include (but are not limited to)
- Exhibit pattern (Avdi Grimm, Object on Rails)
- Command-Query Responsibility Segregation
The best part is. This is live production code written and maintained. By spring 2015 I believe I have gotten some insights about the work, which I am happy to share with.
The talk would be about showing real production code using the pattern. And controllers & views with very few if-statements.
Who is it for?
Programmer
Co-Founder
Leader
Consultant
Audience Learnings
Eliminate if-statements from controllers and views with object-oriented views approach
Structure
- Introduction
- Case-study
- Findings
Prerequisites
None
Leave a Reply