Shared library for iPhone and BlackBerry

I have a set of functionalities (classes) that I would like to share with the application that I create for iPhone and for Blackberry (Java). Does anyone have any best practices on this?

+4
source share
4 answers

It will not be possible, as far as I understand your question: the binary format for iPhone and Java is incompatible - and even for the native library on the Blackberry device.

This is not like creating for OS X, where you can use Java unreasonably, the iPhone does not support Java.

The best idea is probably to create a library in Objective-C and then port it to Java, which is an easier transition than another. If you program for Objective-C and make sure that the code has no memory leaks, then the changes are not so complicated.

If you keep the structure of your classes the same, you should find maintenance much easier - fix the error in Java and it will be easy for you to check the same error in ObjC methods, etc.

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

+4
source

As Grouchal mentioned, you won’t 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 the application if you carefully separate it into highly decoupled layers. This is still a big win, because the logical design of the application probably makes up a significant part of your development efforts.

You could wrap sections of the platform’s interfaces (iPhone SDK, etc.) that you use with your own interfaces. In doing so, you effectively hide platform-specific libraries and simplify the management of your design and code when dealing with platform differences.

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

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

This in itself will make the application more understandable for different platforms. Of course, the code will always look different around the edges, i.e. When you begin to deal with presentation, streams, networks, etc. However, these problems will be handled by your API shells, which were once developed, that should have fairly static interfaces.

You can also win if you later add developers further applications that need to be delivered to both platforms, as you may find that you can reuse or extend your API wrappers.

+4
source

If you are writing a client-server application, you should also try to save as much logic as possible on your server. Keep the amount of additional business logic on the device to a minimum. The more you can consider a device as a presentation layer, the less you will carry it over to everything.

Also, following the same naming conventions and package structure in all projects helps a lot, especially for your infrastructure code.

The APIs and usability interfaces for BlackBerry and iPhone are so different that in most cases it will not be possible to directly connect this logic between applications. The biggest mistake, in my opinion, was to try to transfer the user interface intended for one mobile platform to another. The way people interact with BlackBerrys vs iPhones is very different, so be prepared to update your user interface for every mobile platform on which you want to deploy.

Hope this will be helpful.

+3
source

You can write C ++ code that works both in the BB10 Native app and in the iOS app. Xcode will need to see C ++ files as ObjectiveCPP code.

I am currently working on such a task in my free time. I have not finished it enough to show or find out if this is really possible, but I have not hit any road blocks yet.

You will need to be disciplined to write good cross-platform code designed with abstractions for platform-specific functions.

My general model is that I have a “Foo class” for working with cross-platform and a “FooPlatform class” to do platform-specific things. The Foo class can call the FooPlatform class, which abstracts any particular platform.

Raw cross-platform code alone does not compile. Separate BB10 and Xcode projects are created in the corresponding IDE. Each project implements a thin (several [dozen] lines) "class FooPlatform" and refers to the raw cross-platform code.

When I get something that I can show, I will post again here ...

0
source

Source: https://habr.com/ru/post/1286465/


All Articles