Chapter 5
Building Shared Applications
What's in this Chapter?
- Reviewing how to drive model design from user experience
- Walking through explicit model examples
- Understanding the controller's function
The model and controller are at the heart of an MVC application. For cross-platform applications, developers can reap more benefits from code portability by leveraging the model and controller classes to do the heavy lifting. Routines for verifying data input, logic trees, navigations flows, and data loading are all best placed in either the controller or the model. Such a practice results in the most reusable code.
Because you implement views independently on each platform, you can rarely leverage code written for one view when writing that same view for another platform. This is because each platform's UI classes and constructs are not shared. In iOS the UIView and its subclasses make up the large portion of the built-in controls. As might be expected, Android and Windows Phone 7 don't have a UIView class. For Android OS the Activity class serves as the root container for UI controls. In Windows Phone 7 the Silverlight Canvas classes sit at the base of UI controls.
At first it can seem obvious and easy to keep business logic out of the view. But every time a control verifies a value entered, every time a UI action updates a model's value, and every time a touch event causes a navigation event, the code must be rewritten in each platform's view. The navigation events are the secret ...