关于跨平台项目中的网络语言互操作性的问题

Jea*_*ent 5 architecture frontend android cross-platform ios

我计划在iOS,Android和AngularJS网站上创建一个应用程序.

但是,由于不必在每个应用程序上重写业务代码,我希望尽可能多地重用代码.

为了能够在任何平台上执行项目的核心,我必须使用Web语言.

通过不同的文章,我计划一个通用的架构来分离项目的业务逻辑 - 核心 - 与将为每个系统重新实现的UI(UIKit for iOS,AngularJS和Polymer for webapp等)

该体系结构的目标是通过分解模块中的需求,DRYSOLID来尊重重要的软件工程原理,例如信息隐藏

  • 每个功能都将在模块中分解.
  • Core: Business logic code - reusable on every platform - will be represented in form of a library.
  • View: The view class will be developed on each different platform to use the different UI elements proposed on each platform. E.g.: subclass of a ViewController in Objective-C/Swift for iOS or a simple class to manipulate HTML for the web-app. There is no logic in this class. It is only responsible to:
    • Handle user interactions to the business logic.
    • Display contents from the business logic
  • IView: Interface which abstracts the class which manipulates the view.
  • Presenter: Link between the Interactor and the View to drive the UI.
  • Interactor: The logic of the module, such as algorithms.
  • Data Store: Manage the persistence and the fetching of data by communicating with a database or API or web-service.
  • Model: Data represented in structures.

Here for iOS (almost the same for Android):

在此输入图像描述

The code of "core" will be executed through a virtual machine as this article shows us: http://www.skyscanner.net/blogs/developing-mobile-cross-platform-library-part-3-javascript

Here for AngularJS:

https://docs.google.com/drawings/d/1NtdDfsr1yiuGOm_lfOY6Qab_kHb4I5b4sx7zeTAqwrE/pub?w=915&h=377


Now that you know everything about the architecture, here are my questions.

I don't have enough experiences and feedback on the web-langages to be able to make a smart choice. After few researches, I found that there are various options:

  • Dart:

    • Question 1: Are there mechanisms to allow interoperability between Objective-C/Swift and Java through VM? I know that both platforms have VM to execute Javascript code and Google provides dart2js to compile Dart to Javascript code. But it's not plain Javascript: See an example here. So I don't know if there is still a proper interoperability.
  • Javascript ES6: Event if it's not fully implemented in browsers yet, it's possible to start using ES6 with Traceur compiler.

    • Question 2: Is there interoperability of Javascript compiled by Traceur and the VM in iOS/Android?
    • Question 3: Is it "safe" to use ES6 through Traceur to develop a large-scale project and have production code?

谢谢你的阅读.

Lex*_*hny 2

我知道这不是您列出的选项之一,但不会自动排除 C++。例如,这就是 Dropbox 使用的方法,他们甚至为此目的开源了他们的工具:

C++ 到 Java/Objective-C API 生成器:

https://github.com/dropbox/djinni

适用于 Android/iOS 的示例“本机”应用程序:

https://github.com/libmx3/mx3

关于该主题的有趣文章有更多链接:

http://oleb.net/blog/2014/05/how-dropbox-uses-cplusplus-cross-platform-development/

更新答案:

如果您确实不想使用 C++ 并且可以接受非本地语言带来的臃肿,那么您可以尝试以下操作:

https://github.com/MobileChromeApps/mobile-chrome-apps

该项目是 Google 的 Cordova 分支,并添加了许多新功能和优点。

这里有一个 Chrome API 的 Dart 包装器:

https://github.com/dart-gde/chrome.dart

基本上,您可以使用纯 HTML5 技术在 Dart 中编写应用程序,然后对于某些事情您可以使用 Chrome API(设备状态等)。然后您可以部署:

  • Web:编译为 JavaScript,无需 Chrome API 功能。
  • Chrome 操作系统:使用 Chrome API 功能编译为 JavaScript。
  • Android:编译为 JavaScript,然后使用 MobileChromeApps 创建 Android 应用程序。
  • iOS:编译为 JavaScript,然后使用 MobileChromeApps 创建 iOS 应用程序。