Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Common code base across native iOS, Android and Windows Phone App

Is it possible to encapsulate business rules (no presentation layer) into a common code base to be used by native iOS, Android and Windows Phone apps? In other words, if I was writing a game to be developed across all mobile platforms, could I write a library in C or C++ which handles all the game rules (e.g. is this a valid move) and have all platforms use this library (compiled natively on each client). Please note, this would be not be for any UI/presentation code. And I am not interested in using any of the cross-platform development tools (PhoneGap, etc).

My question is, a) is this possible, b) what languages can this be done in, and c) is this a good idea? While it would add some complexity to each client up front I'm thinking it would greatly reduce the amount of code to write (less bugs) and maintenance over time.

like image 851
Joel Avatar asked Oct 21 '22 18:10

Joel


1 Answers

The two answers are I can find are C++ and JavaScript as languages that can be understood by all three platforms.

C++:

  • Windows
  • Android
  • iOS

JavaScript:

  • all support through their browser widget (WebView), though I only listed this for completeness.

I personally have not attempted to include C++ files in my apps, so mileage my vary, but the capabilities seem to be there. It doesn't seem to be a bad idea, though; on its face, it seems that a library that does business logic shouldn't have a lot of trouble on any platform, and you'll be certain that all platforms are always in sync. The one thing I would say to watch out for is performance; Android and Windows Phone seem like they might be slow if you set things up incorrectly.

like image 161
Hylianpuffball Avatar answered Oct 23 '22 09:10

Hylianpuffball