lmirosevic
lmirosevic

Reputation: 16307

Best way to write common code for Objective-C and Java?

I am simultaneously developing native applications for both Android and iOS. I know there is no "good" way to write code once and have it run on both platforms--technically yes, I could use Phonegap, but from a user standpoint they wouldn't feel like native apps due to the differences in the platform.

But is there a way to share subsets of controller code between the two platforms? I am talking about the "invisible" code, i.e. code that has nothing to do with (directly) drawing the UI and does not use the iOS and Android frameworks. For example if I was developing Angry Birds, what's the best way to implement the physics equations governing the flight trajectory of the birds? How do I best share this kind of code between the two platforms? By "best" I mean how can I 1)minimise development time, 2)simplify maintenance and 3)simplify future upgrades.

Upvotes: 2

Views: 308

Answers (2)

victor.t
victor.t

Reputation: 454

Options I see:

  1. Using server side to compute logic and then any UI can display it no matter on what platform. This option however will require network connection or may have slow response due to ping.

  2. Write common code in C/C++. This option is more complicated but it will work in 100% cases as c/c++ compiles to native code that means it's supported by almost all operating systems.

  3. Write common code in scripting language like Python, LUA ... This one will require interpreter on client side. Also there's can be performance issues if you'll execute scrip on each frame and do complicated logic in it.

  4. Using phoneGap/ mono/ marmelade ... This will limit native functionality and you'll always depend on 3rd party and not on native SDK. But if you developing openGL es game maybe marmelade is the way to go.

On my opinion C/C++ is the way to go, especially if you are developing a game and don't want to limit yourself to one platform.

PS: If I was developing game like angry birds I would use BOx2d and not implementing physics by myself.

EDIT: Native code only supported on windows phone 8

Upvotes: 2

Jay Wardell
Jay Wardell

Reputation: 2290

Writing in C may be the answer.

Objective C is just a superset of C, and you can write your model layer as just a wrapper of c functions.

According to this article, you can do something very similar in Android using JNI.

As you say, this is only possible for the model layer. You'll have to write Objective C for the view and controller layers in iOS, and you'll be in the same situation on Android.

Upvotes: 0

Related Questions