Re:The Second Edition of “Refactoring”
by goto11 on Sunday December 02, 2018 @08:49AM
(#18582282)
But then the 'Student' object does not represent a student but represent the result of a search which may or may not be a student, and this result decides its own view. Effectively the model is coupled to a specific view, which seems wrong to me. I would much prefer to have the search return an Option<Student> and then have the controller select the view based on this option. This also makes it explicit that the search may nor return a result, which is not really explicit if it always returns a Student instance.
[ Parent
| on HN ]
Note the explicit change to StudentSearchResult over student there to make your last comment kind of a yes, I agree and that was the intent...
There are many ways that this can be implemented that avoid an if result != null / == no value, often a map suffices.