作者:洋紫儿__来丶了 | 来源:互联网 | 2023-05-24 13:15
我计划在iOS,Android和AngularJS网站上创建一个应用程序.
但是,由于不必在每个应用程序上重写业务代码,我希望尽可能多地重用代码.
为了能够在任何平台上执行项目的核心,我必须使用Web语言.
通过不同的文章,我计划一个通用的架构来分离项目的业务逻辑 - 核心 - 与将为每个系统重新实现的UI(UIKit for iOS,AngularJS和Polymer for webapp等)
该体系结构的目标是通过分解模块中的需求,DRY和SOLID来尊重重要的软件工程原理,例如信息隐藏
每个功能都将在模块中分解.
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:
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?
谢谢你的阅读.