Developing in Layers
For a long time i have been using a scheme of things in developing UIs which has started to bug me, literally in every sense of the word. What i do is this:
For any page/view, i create the control, which in essence is a form or a configuration controller. Now, this control is independent from everything else, and i can use it as i deem fit. It has its own set of hooks using which i can feed and retrieve information from it. Mind you, these controls are very specific to the application itself and do not form a very integral part of a generic sdk. So, the freedom i get with these controls is absolute flexibility. I can place them in a page, a view, a pop up or a sidebar. But the only issue is that i have to play with some ground rules. Just one ground rule actually: I cannot make service calls from any of these controls. Like i discussed this in a previous post of mine in detail, doing so makes the control tightly bound with the service or the backend, hence limiting its usability in another part of the application. While this gives me a lot of freedom of where and how i want my UI to appear and look it gives me hell when i sit down to develop most of my app.
The scenario is thus: I have a page which acts as an empty shell. It has nothing in it at the beginning, barring a label which designates its purpose in the near future. Hence i create an empty shell. Then i make my control which i can fit/embed anywhere in the page. Its like playing with building blocks after a point. While i have that flexibility i cannot deal with the hell of maintaining the code base when i have to handle a Pop up inside a Page which is arrived at from another Page and all these Pages and Pop-ups are tightly coupled with each other in terms of the information they show right down to the last Label, and mind you all these Pops and Pages have their own controls. Hence assuming every view has an empty shell (read popup/page), and each of these shells has a minimum of one control, i have to manage around 2xN modules of code for N views, with each Module having a Markup File and a Code Behind making it 2x2xN. FOUR TIMES the number of Views i have in my application.
Why would i do it you ask? I would do it simply because the shell itself seems to change. One day the control looks better in a page. Another day God comes down to earth and advices to place it in a Pop up. And then all of a sudden tooth fairy throws a tantrum saying that she wants it in the bloody Side Bar. I curse each and every day when i lost a tooth. Earlier it was due to the pain of it. Today it is because of tooth fairy's tantrums. And the contents of the last few lines are a blunt and candid indicator of how deranged i have become with the code and its maintainability.
The Solution: Call me if you have one.
The Lesson: I can not reiterate this enough in my blog posts, but for heavens' and sanity's sakes, plan and think through the UI before developing it.