views:

198

answers:

3

Hi,

I'm currently implementing a Monotouch application that will eventually be ported to Monodroid. The application is just a client to an OData Web service. Nothing too fancy or performance critical.

The challenge is to reuse as much code as possible. I'm aware that the UI APIs for Monotouch and Monodroid are quite different, but I'm hoping to to reuse the data data abstraction and business layers.

Since my UI layer follows the MVP pattern, I also hope to reuse UI controllers by coding an abstract representation of each view. However, I can only guess if this will work since I am not yet allowed to the Monodroid beta.

Now my questions:

  • What do you think about this approach? Is this a good idea, or will it just lead to a mediocre application because of differences in the UI concept between IPhone and Android?

  • Can you offer any hints on how to structure the application to maximize code re-use?

Thanks,

Adrian

+1  A: 

I tried doing something similar - in my case because I wanted to use VS and all my Windows development tools for as much code as possible.

However, I reverted to just having the model layer being "generic" - and doing the UI layer (controllers and views) on the Mac (i.e. in MonoDevelop). The effort involved was overkill for the relatively small application I was working on - and only I was the only one working on it.

Also, if you are new to the iPhone and/or Android, trying to do something relatively sophisticated will make it more difficult to find samples or get answers to questions. I found I was making life harder for myself (certainly in the early days of my iPhone work).

Of course, without knowing the ins and outs of your project(s) and business model, it's difficult to give any concrete advice, but those were my experiences - for what they're worth.

dommer
Hearing about your experiences does definitely help. Thanks for your reply!
Adrian Grigore
+3  A: 

What do you think about this approach? Is this a good idea, or will it just lead to a mediocre application because of differences in the UI concept between IPhone and Android?

I would say the latter, but you can definitely re-use a large portion of your business and domain objects. The same Mono Sqlite is used in Monodroid, so the data persistence part of your app (if it uses that) is re-usable.

I wouldn't bother creating a middle layer UI - the two are completely different. For example on Android apps you have the bottom menu, which can contain 6 buttons on screen. On the iPhone you are more than likely not to have 6 buttons in a tab bar or toolbar. To make a common pattern for that won't help you much.

Another example is ListViews (UITableViews). They're completely different. As you'd expect the Monodroid implementation is faithful to its ugly Java sister. On Android you don't have to use the huge tangle of indirection that Apple force upon you, but just a simple ArrayAdapter as the data source - subclassed for more complicated layouts.

Another important thing to note is Android doesn't have one screen size. You create images for 3 different screen densities. Font sizes aren't absolute.

Android provides you with layout mechanisms similar to XAML and the web, on the iPhone you're not so lucky (or more fortunate, depending how you view it) as everything is generally absolutely positioned (they can do this as it's always 320x480).

Can you offer any hints on how to structure the application to maximize code re-use?

I think you've got most of covered with separate layers for the data and sticking to controllers. Without seeing your app it's hard to say how easy it will be re-use the controllers (whether you use UITableViews or custom uis), but Android is so much faster to develop with I think it should be a quick task.

(I'm on the Monodroid preview and also have a MT apps out)

Chris S