Can anyone suggest design pattern to separate busi

2019-04-12 09:19发布

I am going to develop mobile web application. App will use web services for back-end data. All presentation and business logic needs to write in javascript.

There is different design in ios and android.

And don't want to rewrite business logic separately for both.

Can anyone suggest design pattern to separate business logic and presentation logic in JavaScript.

4条回答
We Are One
2楼-- · 2019-04-12 09:39

I am using Sencha Touch, as it allows me to seperate iOS, Android, and tablets. Plus it supports REST-ful and JSONP to do as you want.

查看更多
混吃等死
3楼-- · 2019-04-12 09:44

Sencha Touch is the best choices i think. Not only give you separation between presentation and bussiness logic, it also cross browser especially Android, iPhone , and Blackberry 6. By using sencha touch, it give you easy acces to deploy your mobile web app to native web app by using phonegap

查看更多
我欲成王,谁敢阻挡
4楼-- · 2019-04-12 09:51

take a look at backbone.js, it's a superb MVC framework for rich javascript applications.

查看更多
Luminary・发光体
5楼-- · 2019-04-12 09:55

A good design pattern is to design a "REST-ful" API for storing, retrieving, and modifying the data that the application operates on. Then design separate user interfaces that share this common API. When writing the code, use separate prototypes and functions for representing and manipulating the data from the prototypes used to represent the way the data looks or is controlled in the user interface.

You can also achieve reusability by using CSS to control the appearance of your application on iOS and Android, while still using the same HTML DOM structure in both versions of the application. In other words, you can get more reusability by manipulating the "class" attribute of the DOM elements rather than explicitly modifying the "style" attribute, relying on the CSS to apply the style based on the class. Then, for the most part, you can get away with using the same JavaScript code, but simply providing different versions of the CSS to the different user agents. There may be cases where additional differences show up; I simply suggest refactoring them into their own functions as they show up.

As others have pointed out, there are a number of existing JavaScript frameworks (such as Sencha Touch) that already abstract the view logic for mobile devices, allowing you to just write the model and control parts of the logic. If you have an abstraction for the UI components, then the only separation that would need to be maintained is the one between the model and the controller.

查看更多
登录 后发表回答