views:

725

answers:

3

I have a set of functionality (classes) that I would like to share with an application I'm building for the iPhone and for the Blackberry (Java). Does anyone have any best practices on doing this?

+4  A: 

This is not going to be possible as far as I understand your question - the binary format for the iPhone and Java are not compatible - and even for a native library on a blackberry device.

This is not like building for OS X where you can use Java unfornately the iPhone doesn't support Java.

The best idea is probably to build you library in Objective-C and then port it to Java which is an easier transition than going the other way. If you programme for Objective-C and make sure you code has no memory leaks - then the changes are not so complex.

If you keep the structure of your classes the same then you should find maintenance much simpler - fix a bug in the Java and you should find it easy to check for the same bug in the ObjC methods etc.

Hope this helps - sorry that it is not all good news.

Grouchal
This does help. I've edited my post a little. I'm more looking for a best practice than the ability to share a binary. The memory leak guidance is exactly the kind of information I'm looking for.
Cody C
I agree with teabot - anything that you can do to make the design similar will be a big win.
Grouchal
+4  A: 

As Grouchal mentioned - you are not going to be able to share any physical components of your application between the two platforms. However you should be able to share the logical design of your application if you carefully separate it into highly decoupled layers. This is still a big win because the logical application design probably accounts for a large part of your development effort.

You could aim to wrap the sections of the platform specific APIs (iPhone SDK etc.) that you use with your own interfaces. In doing so you are effectively hiding the platform specific libraries and making your design and code easier to manage when dealing with differences in the platforms.

With this in place you can write your core application code so that it appears very similar on either platform - even though they are written in different languages. I find Java and Objective-C to be very similar conceptually (at least at the level at which I use it) and would expect to be able to achieve parity with at least the following:

  • An almost identical set of Java and Objective-C classes with the same names and responsibilities
  • Java/Objective-C classes with similarly named methods
  • Java/Objective-C methods with the same responsibilities and logical implementations

This alone will make the application easier to understand across platforms. Of course the code will always look very different at the edges - i.e when you start dealing with the view, threading, networking etc. However, these concerns will be handled by your API wrappers which once developed should have fairly static interfaces.

You might also stand to benefit if you later developer further applications that need to be delivered to both platforms as you might find that you can reuse or extend your API wrappers.

teabot
+3  A: 

If you are writing a client-server type application you should also try and keep as much logic on your server as possible. Keep the amount of extra business logic on the device to a minimum. The more you can just treat the device as a view layer the less porting you'll have to do over all.

Aside from that, following the same naming conventions and package structure across all the projects helps greatly, especially for your framework code.

The UI API's and usability paradigms for BlackBerry and iPhone are so different that it won't be possible in most cases to directly port this kind of logic between apps. The biggest mistake one could make (in my opinion) is to try and transplant a user experience designed for one mobile platform on to another. The way people interact with BlackBerrys vs iPhones is very different so be prepared to revamp your user experience for each mobile platform you want to deploy on.

Hope this is helpful.

Adam B
You are right about the big mistake and making sure that user interaction is consistent on each platform.You comment about putting as much code on the server as possible doesn't always work - it relies on the user having a good connection. I think if your solution is to keep the server doing everything you might be better off writing a web app. If you are going to have a local app the user experience is not good if it needs the server to do core things and the user has no signal.
Grouchal