Views : ViewControllers, many to one, or one to one?
Posted
by
conor
on Programmers
See other posts from Programmers
or by conor
Published on 2012-11-21T10:06:23Z
Indexed on
2012/11/21
11:22 UTC
Read the original article
Hit count: 254
mvc
I have developed an Android application where, typically, each view (layout.xml
) displayed on the screen has it's own corresponding fragment (for the purpose of this question I may refer to this as a ViewController
).
These views and Fragments/ViewControllers are appropriately named to reflect what they display. So this has the effect of allowing the programmer to easily pinpoint the files associated with what they see on any given screen.
The above refers to the one to one part of my question.
Please note that with the above there are a few exceptions where very similar is displayed on two views so the ViewController
is used for two views. (Using a simple switch (type) to determine what layout.xml
file to load)
On the flip side. I am currently working on the iOS version of the same app, which I didn't develop. It seems that they are adopting more of a one-to-many (ViewController
:View
) approach.
There appears to be one ViewController
that handles the display logic for many different types of views. In the ViewController
are an assortment of boolean flags and arrays of data (to be displayed) that are used to determine what view to load and how to display it.
This seems very cumbersome to me and coupled with no comments/ambiguous variable names I am finding it very difficult to implement changes into the project.
What do you guys think of the two approaches? Which one would you prefer? I'm really considering putting in some extra time at work to refactor the iOS into a more 1:1 oriented approach.
My reasoning for 1:1 over M:1 is that of modularity and legibility. After all, don't some people measure the quality of code based on how easy it is for another developer to pick up the reigns or how easy it is to pull a piece of code and use it somewhere else?
© Programmers or respective owner